[Git][java-team/plexus-resources][upstream] New upstream version 1.3.0+really1.1.0
Pierre Gruet (@pgt)
gitlab at salsa.debian.org
Sat Apr 12 11:27:00 BST 2025
Pierre Gruet pushed to branch upstream at Debian Java Maintainers / plexus-resources
Commits:
6a2b1650 by Pierre Gruet at 2025-04-12T11:41:30+02:00
New upstream version 1.3.0+really1.1.0
- - - - -
29 changed files:
- − .github/dependabot.yml
- − .github/release-drafter.yml
- − .github/workflows/maven.yml
- − .github/workflows/release-drafter.yml
- .gitignore
- − LICENSE
- − README.md
- pom.xml
- src/main/java/org/codehaus/plexus/resource/DefaultResourceManager.java
- src/main/java/org/codehaus/plexus/resource/PlexusResource.java
- src/main/java/org/codehaus/plexus/resource/ResourceManager.java
- src/main/java/org/codehaus/plexus/resource/loader/AbstractResourceLoader.java
- src/main/java/org/codehaus/plexus/resource/loader/FilePlexusResource.java
- src/main/java/org/codehaus/plexus/resource/loader/FileResourceCreationException.java
- src/main/java/org/codehaus/plexus/resource/loader/FileResourceLoader.java
- src/main/java/org/codehaus/plexus/resource/loader/JarHolder.java
- src/main/java/org/codehaus/plexus/resource/loader/JarResourceLoader.java
- src/main/java/org/codehaus/plexus/resource/loader/ResourceIOException.java
- src/main/java/org/codehaus/plexus/resource/loader/ResourceLoader.java
- src/main/java/org/codehaus/plexus/resource/loader/ResourceNotFoundException.java
- src/main/java/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoader.java
- src/main/java/org/codehaus/plexus/resource/loader/URLPlexusResource.java
- src/main/java/org/codehaus/plexus/resource/loader/URLResourceLoader.java
- src/test/java/org/codehaus/plexus/resource/ResourceManagerTest.java
- src/test/java/org/codehaus/plexus/resource/loader/AbstractResourceLoaderTest.java
- src/test/java/org/codehaus/plexus/resource/loader/FileResourceLoaderTest.java
- src/test/java/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoaderTest.java
- src/test/java/org/codehaus/plexus/resource/loader/URLResourceLoaderTest.java
- src/test/java/org/codehaus/plexus/resource/loader/manager/ResourceManagerTest.java
Changes:
=====================================
.github/dependabot.yml deleted
=====================================
@@ -1,10 +0,0 @@
-version: 2
-updates:
- - package-ecosystem: "maven"
- directory: "/"
- schedule:
- interval: "daily"
- - package-ecosystem: "github-actions"
- directory: "/"
- schedule:
- interval: "daily"
=====================================
.github/release-drafter.yml deleted
=====================================
@@ -1,2 +0,0 @@
-_extends: .github
-tag-template: plexus-resources-$NEXT_MINOR_VERSION
=====================================
.github/workflows/maven.yml deleted
=====================================
@@ -1,31 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-name: GitHub CI
-
-on: [push, pull_request]
-
-jobs:
- build:
- name: Build it
- uses: codehaus-plexus/.github/.github/workflows/maven.yml at master
-
- deploy:
- name: Deploy
- needs: build
- uses: codehaus-plexus/.github/.github/workflows/maven-deploy.yml at master
- secrets: inherit
=====================================
.github/workflows/release-drafter.yml deleted
=====================================
@@ -1,12 +0,0 @@
-name: Release Drafter
-on:
- push:
- branches:
- - master
-jobs:
- update_release_draft:
- runs-on: ubuntu-latest
- steps:
- - uses: release-drafter/release-drafter at v5
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
=====================================
.gitignore
=====================================
@@ -5,4 +5,3 @@ target/
bin
*.iml
.idea
-.DS_Store
=====================================
LICENSE deleted
=====================================
@@ -1,201 +0,0 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
=====================================
README.md deleted
=====================================
@@ -1,8 +0,0 @@
-Plexus-Resources
-===============
-
-[](http://www.apache.org/licenses/)
-[](https://search.maven.org/artifact/org.codehaus.plexus/plexus-resources)
-[](https://github.com/codehaus-plexus/plexus-resources/actions/workflows/maven.yml)
-
-The canonical git repository is located at https://github.com/codehaus-plexus/plexus-resources
=====================================
pom.xml
=====================================
@@ -4,13 +4,12 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus</artifactId>
- <version>16</version>
- <relativePath />
+ <artifactId>plexus-components</artifactId>
+ <version>4.0</version>
</parent>
<artifactId>plexus-resources</artifactId>
- <version>1.3.0</version>
+ <version>1.1.0</version>
<name>Plexus Resource Component</name>
<description>A component to transparently retrieve resources from the filesystem, classpath or internet.</description>
@@ -18,8 +17,8 @@
<scm>
<connection>scm:git:git at github.com:codehaus-plexus/plexus-resources.git</connection>
<developerConnection>scm:git:git at github.com:codehaus-plexus/plexus-resources.git</developerConnection>
- <tag>plexus-resources-1.3.0</tag>
<url>http://github.com/codehaus-plexus/plexus-resources</url>
+ <tag>plexus-resources-1.1.0</tag>
</scm>
<issueManagement>
<system>jira</system>
@@ -32,20 +31,6 @@
</site>
</distributionManagement>
- <properties>
- <project.build.outputTimestamp>2023-12-23T22:05:19Z</project.build.outputTimestamp>
- <mockito.version>4.11.0</mockito.version>
- </properties>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- <version>4.0.0</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
@@ -53,76 +38,61 @@
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-xml</artifactId>
- <version>3.0.0</version>
- </dependency>
- <dependency>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- <version>1</version>
+ <artifactId>plexus-container-default</artifactId>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.36</version>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-annotations</artifactId>
+ <optional>true</optional>
</dependency>
-
+
<!-- TEST -->
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
- <version>${mockito.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-junit-jupiter</artifactId>
- <version>${mockito.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.simplify4u</groupId>
- <artifactId>slf4j-mock</artifactId>
- <version>2.3.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-testing</artifactId>
- <version>1.3.0</version>
+ <version>1.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.4</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
<configuration>
- <content>${project.reporting.outputDirectory}</content>
- <!-- mono-module doesn't require site:stage -->
+ <content>${project.reporting.outputDirectory}</content><!-- mono-module doesn't require site:stage -->
</configuration>
<executions>
<execution>
<id>scm-publish</id>
- <!-- deploy site with maven-scm-publish-plugin -->
+ <phase>site-deploy</phase><!-- deploy site with maven-scm-publish-plugin -->
<goals>
<goal>publish-scm</goal>
</goals>
- <phase>site-deploy</phase>
</execution>
</executions>
</plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
<plugin>
- <groupId>org.eclipse.sisu</groupId>
- <artifactId>sisu-maven-plugin</artifactId>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>3.0.4</version>
</plugin>
</plugins>
- </build>
+ </reporting>
+
</project>
=====================================
src/main/java/org/codehaus/plexus/resource/DefaultResourceManager.java
=====================================
@@ -24,173 +24,204 @@ package org.codehaus.plexus.resource;
* SOFTWARE.
*/
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Map;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.resource.loader.FileResourceCreationException;
import org.codehaus.plexus.resource.loader.ResourceIOException;
import org.codehaus.plexus.resource.loader.ResourceLoader;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Map;
/**
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @author Jason van Zyl
* @version $Id$
*/
- at Named
-public class DefaultResourceManager implements ResourceManager {
- private static final Logger LOGGER = LoggerFactory.getLogger(DefaultResourceManager.class);
-
- private final Map<String, ResourceLoader> resourceLoaders;
+ at Component( role = ResourceManager.class, instantiationStrategy = "per-lookup" )
+public class DefaultResourceManager
+ extends AbstractLogEnabled
+ implements ResourceManager
+{
+ @Requirement( role = ResourceLoader.class )
+ private Map<String, ResourceLoader> resourceLoaders;
private File outputDirectory;
- @Inject
- public DefaultResourceManager(Map<String, ResourceLoader> resourceLoaders) {
- this.resourceLoaders = resourceLoaders;
- }
-
// ----------------------------------------------------------------------
// ResourceManager Implementation
// ----------------------------------------------------------------------
- @Override
- public InputStream getResourceAsInputStream(String name) throws ResourceNotFoundException {
- PlexusResource resource = getResource(name);
- try {
+ public InputStream getResourceAsInputStream( String name )
+ throws ResourceNotFoundException
+ {
+ PlexusResource resource = getResource( name );
+ try
+ {
return resource.getInputStream();
- } catch (IOException e) {
- throw new ResourceIOException("Failed to open resource " + resource.getName() + ": " + e.getMessage(), e);
+ }
+ catch ( IOException e )
+ {
+ throw new ResourceIOException( "Failed to open resource " + resource.getName() + ": " + e.getMessage(), e );
}
}
- @Override
- public File getResourceAsFile(String name) throws ResourceNotFoundException, FileResourceCreationException {
- return getResourceAsFile(getResource(name));
+ public File getResourceAsFile( String name )
+ throws ResourceNotFoundException, FileResourceCreationException
+ {
+ return getResourceAsFile( getResource( name ) );
}
- @Override
- public File getResourceAsFile(String name, String outputPath)
- throws ResourceNotFoundException, FileResourceCreationException {
- if (outputPath == null) {
- return getResourceAsFile(name);
+ public File getResourceAsFile( String name, String outputPath )
+ throws ResourceNotFoundException, FileResourceCreationException
+ {
+ if ( outputPath == null )
+ {
+ return getResourceAsFile( name );
}
- PlexusResource resource = getResource(name);
+ PlexusResource resource = getResource( name );
File outputFile;
- if (outputDirectory != null) {
- outputFile = new File(outputDirectory, outputPath);
- } else {
- outputFile = new File(outputPath);
+ if ( outputDirectory != null )
+ {
+ outputFile = new File( outputDirectory, outputPath );
+ }
+ else
+ {
+ outputFile = new File( outputPath );
}
- createResourceAsFile(resource, outputFile);
+ createResourceAsFile( resource, outputFile );
return outputFile;
}
- @Override
- public File resolveLocation(String name, String outputPath) {
+ public File resolveLocation( String name, String outputPath )
+ throws IOException
+ {
// Honour what the original locator does and return null ...
- try {
- return getResourceAsFile(name, outputPath);
- } catch (Exception e) {
+ try
+ {
+ return getResourceAsFile( name, outputPath );
+ }
+ catch ( Exception e )
+ {
return null;
}
}
- @Override
- public File resolveLocation(String name) {
+ public File resolveLocation( String name )
+ throws IOException
+ {
// Honour what the original locator does and return null ...
- try {
- return getResourceAsFile(name);
- } catch (Exception e) {
+ try
+ {
+ return getResourceAsFile( name );
+ }
+ catch ( Exception e )
+ {
return null;
}
}
- @Override
- public void setOutputDirectory(File outputDirectory) {
+ public void setOutputDirectory( File outputDirectory )
+ {
this.outputDirectory = outputDirectory;
}
- @Override
- public void addSearchPath(String id, String path) {
- ResourceLoader loader = resourceLoaders.get(id);
+ public void addSearchPath( String id, String path )
+ {
+ ResourceLoader loader = (ResourceLoader) resourceLoaders.get( id );
- if (loader == null) {
- throw new IllegalArgumentException("unknown resource loader: " + id);
+ if ( loader == null )
+ {
+ throw new IllegalArgumentException( "unknown resource loader: " + id );
}
- loader.addSearchPath(path);
+ loader.addSearchPath( path );
}
- @Override
- public PlexusResource getResource(String name) throws ResourceNotFoundException {
- for (ResourceLoader resourceLoader : resourceLoaders.values()) {
- try {
- PlexusResource resource = resourceLoader.getResource(name);
+ public PlexusResource getResource( String name )
+ throws ResourceNotFoundException
+ {
+ for ( ResourceLoader resourceLoader : resourceLoaders.values() )
+ {
+ try
+ {
+ PlexusResource resource = resourceLoader.getResource( name );
- LOGGER.debug("The resource '{}' was found as '{}'", name, resource.getName());
+ getLogger().debug( "The resource " + "'" + name + "'" + " was found as " + resource.getName() + "." );
return resource;
- } catch (ResourceNotFoundException e) {
- LOGGER.debug(
- "The resource '{}' was not found with resourceLoader '{}'",
- name,
- resourceLoader.getClass().getName());
+ }
+ catch ( ResourceNotFoundException e )
+ {
+ getLogger().debug(
+ "The resource " + "'" + name + "'" + " was not found with resourceLoader "
+ + resourceLoader.getClass().getName() + "." );
}
}
- throw new ResourceNotFoundException(name);
+ throw new ResourceNotFoundException( name );
}
- @Override
- public File getResourceAsFile(PlexusResource resource) throws FileResourceCreationException {
- try {
+ public File getResourceAsFile( PlexusResource resource )
+ throws FileResourceCreationException
+ {
+ try
+ {
File f = resource.getFile();
- if (f != null) {
+ if ( f != null )
+ {
return f;
}
- } catch (IOException e) {
+ }
+ catch ( IOException e )
+ {
// Ignore this, try to make use of resource.getInputStream().
}
- final File outputFile = FileUtils.createTempFile("plexus-resources", "tmp", outputDirectory);
+ final File outputFile = FileUtils.createTempFile( "plexus-resources", "tmp", outputDirectory );
outputFile.deleteOnExit();
- createResourceAsFile(resource, outputFile);
+ createResourceAsFile( resource, outputFile );
return outputFile;
}
- @Override
- public void createResourceAsFile(PlexusResource resource, File outputFile) throws FileResourceCreationException {
+ public void createResourceAsFile( PlexusResource resource, File outputFile )
+ throws FileResourceCreationException
+ {
InputStream is = null;
OutputStream os = null;
- try {
+ try
+ {
is = resource.getInputStream();
File dir = outputFile.getParentFile();
- if (!dir.isDirectory() && !dir.mkdirs()) {
- throw new FileResourceCreationException("Failed to create directory " + dir.getPath());
+ if ( !dir.isDirectory() && !dir.mkdirs() )
+ {
+ throw new FileResourceCreationException( "Failed to create directory " + dir.getPath() );
}
- os = new FileOutputStream(outputFile);
- IOUtil.copy(is, os);
+ os = new FileOutputStream( outputFile );
+ IOUtil.copy( is, os );
is.close();
is = null;
os.close();
os = null;
- } catch (IOException e) {
- throw new FileResourceCreationException("Cannot create file-based resource:" + e.getMessage(), e);
- } finally {
- IOUtil.close(is);
- IOUtil.close(os);
+ }
+ catch ( IOException e )
+ {
+ throw new FileResourceCreationException( "Cannot create file-based resource:" + e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( is );
+ IOUtil.close( os );
}
}
+
}
=====================================
src/main/java/org/codehaus/plexus/resource/PlexusResource.java
=====================================
@@ -33,10 +33,11 @@ import java.net.URL;
/**
* A resource is a byte stream, possibly (but not necessarily) with additional attributes like {@link File}, {@link URL}
* , or {@link URI}.
- *
+ *
* @since 1.0-alpha-5
*/
-public interface PlexusResource {
+public interface PlexusResource
+{
/**
* <p>
* Returns the resource as an {@link InputStream}. In general, you should not assume, that this method may me called
@@ -48,43 +49,47 @@ public interface PlexusResource {
* If you need a reliable way of reloading the resource more than once, then you should use
* {@link ResourceManager#getResourceAsFile(PlexusResource)}.
* </p>
- *
+ *
* @return An {@link InputStream} with the resources contents, never null.
*/
- InputStream getInputStream() throws IOException;
+ public InputStream getInputStream()
+ throws IOException;
/**
* <p>
* Returns the resource as a file, if possible. A resource doesn't need to be available as a file: If you require a
* file, use {@link ResourceManager#getResourceAsFile(PlexusResource)}.
* </p>
- *
+ *
* @return A {@link File} containing the resources contents, if available, or null.
*/
- File getFile() throws IOException;
+ public File getFile()
+ throws IOException;
/**
* <p>
* Returns the resources URL, if possible. A resource doesn't need to have an URL.
* </p>
- *
+ *
* @return The resources URL, if available, or null.
*/
- URL getURL() throws IOException;
+ public URL getURL()
+ throws IOException;
/**
* <p>
* Returns the resources URI, if possible. A resource doesn't need to have an URI.
* </p>
- *
+ *
* @return The resources URI, if available, or null.
*/
- URI getURI() throws IOException;
+ public URI getURI()
+ throws IOException;
/**
* Returns the resources name, if possible. A resources name is a relatively unspecified thing. For example, if the
* resource has an {@link URL}, the name might be created by invoking {@link URL#toExternalForm()}. In the case of a
* {@link File}, it might be {@link File#getPath()}.
*/
- String getName();
+ public String getName();
}
=====================================
src/main/java/org/codehaus/plexus/resource/ResourceManager.java
=====================================
@@ -24,64 +24,74 @@ package org.codehaus.plexus.resource;
* SOFTWARE.
*/
+import java.io.InputStream;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import org.codehaus.plexus.resource.loader.FileResourceCreationException;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
+import org.codehaus.plexus.resource.loader.FileResourceCreationException;
/**
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @author Jason van Zyl
* @version $Id$
*/
-public interface ResourceManager {
- InputStream getResourceAsInputStream(String name) throws ResourceNotFoundException;
+public interface ResourceManager
+{
+ String ROLE = ResourceManager.class.getName();
+
+ InputStream getResourceAsInputStream( String name )
+ throws ResourceNotFoundException;
- File getResourceAsFile(String name) throws ResourceNotFoundException, FileResourceCreationException;
+ File getResourceAsFile( String name )
+ throws ResourceNotFoundException, FileResourceCreationException;
- File getResourceAsFile(String name, String outputFile)
- throws ResourceNotFoundException, FileResourceCreationException;
+ File getResourceAsFile( String name, String outputFile )
+ throws ResourceNotFoundException, FileResourceCreationException;
- void setOutputDirectory(File outputDirectory);
+ void setOutputDirectory( File outputDirectory );
- void addSearchPath(String resourceLoaderId, String searchPath);
+ void addSearchPath( String resourceLoaderId, String searchPath );
/**
* Provides compatibility with the Locator utility used by several Maven Plugins.
- *
+ *
* @deprecated
*/
- File resolveLocation(String location, String localfile) throws IOException;
+ File resolveLocation( String location, String localfile )
+ throws IOException;
/**
* Provides compatibility with the Locator utility used by several Maven Plugins.
- *
+ *
* @deprecated
*/
- File resolveLocation(String location) throws IOException;
+ File resolveLocation( String location )
+ throws IOException;
/**
* Searches for a resource with the given name.
- *
+ *
* @since 1.0-alpha-5
*/
- PlexusResource getResource(String name) throws ResourceNotFoundException;
+ PlexusResource getResource( String name )
+ throws ResourceNotFoundException;
/**
* Returns a file with the given resources contents. If the resource is already available as a file, returns that
* file. Otherwise, a file in the resource managers output directory is created and the resource is downloaded to
* that file.
- *
+ *
* @since 1.0-alpha-5
*/
- File getResourceAsFile(PlexusResource resource) throws FileResourceCreationException;
+ File getResourceAsFile( PlexusResource resource )
+ throws FileResourceCreationException;
/**
* Downloads the resource to the given output file.
- *
+ *
* @since 1.0-alpha-5
*/
- void createResourceAsFile(PlexusResource resource, File outputFile) throws FileResourceCreationException;
+ void createResourceAsFile( PlexusResource resource, File outputFile )
+ throws FileResourceCreationException;
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/AbstractResourceLoader.java
=====================================
@@ -24,35 +24,43 @@ package org.codehaus.plexus.resource.loader;
* SOFTWARE.
*/
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.resource.PlexusResource;
+
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.List;
-
-import org.codehaus.plexus.resource.PlexusResource;
+import java.util.ArrayList;
/**
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @version $Id$
*/
-public abstract class AbstractResourceLoader implements ResourceLoader {
- protected final List<String> paths = new ArrayList<>();
+public abstract class AbstractResourceLoader
+ extends AbstractLogEnabled
+ implements ResourceLoader
+{
+ protected List<String> paths = new ArrayList<String>();
- @Override
- public void addSearchPath(String path) {
- if (!paths.contains(path)) {
- paths.add(path);
+ public void addSearchPath( String path )
+ {
+ if ( !paths.contains( path ) )
+ {
+ paths.add( path );
}
}
- @Override
- @Deprecated
- public InputStream getResourceAsInputStream(String name) throws ResourceNotFoundException {
- PlexusResource resource = getResource(name);
- try {
+ public InputStream getResourceAsInputStream( String name )
+ throws ResourceNotFoundException
+ {
+ PlexusResource resource = getResource( name );
+ try
+ {
return resource.getInputStream();
- } catch (IOException e) {
- throw new ResourceIOException("Failed to open resource " + resource.getName() + ": " + e.getMessage(), e);
+ }
+ catch ( IOException e )
+ {
+ throw new ResourceIOException( "Failed to open resource " + resource.getName() + ": " + e.getMessage(), e );
}
}
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/FilePlexusResource.java
=====================================
@@ -36,35 +36,42 @@ import org.codehaus.plexus.resource.PlexusResource;
/**
* Implementation of {@link PlexusResource} for files.
*/
-public class FilePlexusResource implements PlexusResource {
+public class FilePlexusResource
+ implements PlexusResource
+{
private final File file;
- public FilePlexusResource(File file) {
+ public FilePlexusResource( File file )
+ {
this.file = file;
}
- @Override
- public File getFile() {
+ public File getFile()
+ throws IOException
+ {
return file;
}
- @Override
- public InputStream getInputStream() throws IOException {
- return new FileInputStream(file);
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return new FileInputStream( file );
}
- @Override
- public String getName() {
+ public String getName()
+ {
return file.getPath();
}
- @Override
- public URI getURI() {
+ public URI getURI()
+ throws IOException
+ {
return file.toURI();
}
- @Override
- public URL getURL() throws IOException {
+ public URL getURL()
+ throws IOException
+ {
return file.toURI().toURL();
}
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/FileResourceCreationException.java
=====================================
@@ -25,18 +25,23 @@ package org.codehaus.plexus.resource.loader;
*/
/** @author Jason van Zyl */
-public class FileResourceCreationException extends Exception {
+public class FileResourceCreationException
+ extends Exception
+{
private static final long serialVersionUID = 3203687211821479687L;
- public FileResourceCreationException(String string) {
- super(string);
+ public FileResourceCreationException( String string )
+ {
+ super( string );
}
- public FileResourceCreationException(String string, Throwable throwable) {
- super(string, throwable);
+ public FileResourceCreationException( String string, Throwable throwable )
+ {
+ super( string, throwable );
}
- public FileResourceCreationException(Throwable throwable) {
- super(throwable);
+ public FileResourceCreationException( Throwable throwable )
+ {
+ super( throwable );
}
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/FileResourceLoader.java
=====================================
@@ -24,12 +24,13 @@ package org.codehaus.plexus.resource.loader;
* SOFTWARE.
*/
-import javax.inject.Named;
-
import java.io.File;
import java.io.IOException;
+import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.resource.PlexusResource;
+import org.codehaus.plexus.resource.loader.AbstractResourceLoader;
+import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.util.FileUtils;
/**
@@ -37,61 +38,78 @@ import org.codehaus.plexus.util.FileUtils;
* @author Jason van Zyl
* @version $Id$
*/
- at Named(FileResourceLoader.ID)
-public class FileResourceLoader extends AbstractResourceLoader {
+ at Component( role = ResourceLoader.class, hint = "file", instantiationStrategy = "per-lookup" )
+public class FileResourceLoader
+ extends AbstractResourceLoader
+{
public static final String ID = "file";
// ----------------------------------------------------------------------
// ResourceLoader Implementation
// ----------------------------------------------------------------------
- @Override
- public PlexusResource getResource(String name) throws ResourceNotFoundException {
- for (String path : paths) {
- final File file = new File(path, name);
+ public PlexusResource getResource( String name )
+ throws ResourceNotFoundException
+ {
+ for ( String path : paths )
+ {
+ final File file = new File( path, name );
- if (file.canRead()) {
- return new FilePlexusResource(file);
+ if ( file.canRead() )
+ {
+ return new FilePlexusResource( file );
}
}
- File file = new File(name);
- if (file.isAbsolute() && file.canRead()) {
- return new FilePlexusResource(file);
+ File file = new File( name );
+ if ( file.isAbsolute() && file.canRead() )
+ {
+ return new FilePlexusResource( file );
}
- throw new ResourceNotFoundException(name);
+ throw new ResourceNotFoundException( name );
}
/**
- * @deprecated Use {@link org.codehaus.plexus.resource.ResourceManager#getResourceAsFile(PlexusResource)}.
+ * @deprecated Use {@link org.codehaus.plexus.resource.ResourceManager#getResourceAsFile(PlexusResource )}.
*/
- @Deprecated
- public static File getResourceAsFile(String name, String outputPath, File outputDirectory)
- throws FileResourceCreationException {
+ public static File getResourceAsFile( String name, String outputPath, File outputDirectory )
+ throws FileResourceCreationException
- File f = new File(name);
+ {
+ File f = new File( name );
- if (f.exists()) {
- if (outputPath == null) {
+ if ( f.exists() )
+ {
+ if ( outputPath == null )
+ {
return f;
- } else {
- try {
+ }
+ else
+ {
+ try
+ {
File outputFile;
- if (outputDirectory != null) {
- outputFile = new File(outputDirectory, outputPath);
- } else {
- outputFile = new File(outputPath);
+ if ( outputDirectory != null )
+ {
+ outputFile = new File( outputDirectory, outputPath );
+ }
+ else
+ {
+ outputFile = new File( outputPath );
}
- if (!outputFile.getParentFile().exists()) {
+ if ( !outputFile.getParentFile().exists() )
+ {
outputFile.getParentFile().mkdirs();
}
- FileUtils.copyFile(f, outputFile);
+ FileUtils.copyFile( f, outputFile );
return outputFile;
- } catch (IOException e) {
- throw new FileResourceCreationException("Cannot create file-based resource.", e);
+ }
+ catch ( IOException e )
+ {
+ throw new FileResourceCreationException( "Cannot create file-based resource.", e );
}
}
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/JarHolder.java
=====================================
@@ -39,43 +39,57 @@ import org.codehaus.plexus.resource.PlexusResource;
/**
* A small wrapper around a Jar
- *
+ *
* @author <a href="mailto:daveb at miceda-data.com">Dave Bryson</a>
* @author Jason van Zyl
* @version $Id$
*/
-public class JarHolder {
- private final String urlpath;
+public class JarHolder
+{
+ private String urlpath = null;
private JarFile theJar = null;
private JarURLConnection conn = null;
- public JarHolder(String urlpath) {
+ public JarHolder( String urlpath )
+ {
this.urlpath = urlpath;
- try {
- URL url = new URL(urlpath);
+ init();
+ }
+
+ public void init()
+ {
+ try
+ {
+ URL url = new URL( urlpath );
conn = (JarURLConnection) url.openConnection();
- conn.setAllowUserInteraction(false);
+ conn.setAllowUserInteraction( false );
- conn.setDoInput(true);
+ conn.setDoInput( true );
- conn.setDoOutput(false);
+ conn.setDoOutput( false );
conn.connect();
theJar = conn.getJarFile();
- } catch (IOException ioe) {
+ }
+ catch ( IOException ioe )
+ {
}
}
- public void close() {
- try {
+ public void close()
+ {
+ try
+ {
theJar.close();
- } catch (Exception e) {
+ }
+ catch ( Exception e )
+ {
}
theJar = null;
@@ -83,73 +97,91 @@ public class JarHolder {
conn = null;
}
- public InputStream getResource(String theentry) throws ResourceNotFoundException {
+ public InputStream getResource( String theentry )
+ throws ResourceNotFoundException
+ {
InputStream data = null;
- try {
- JarEntry entry = theJar.getJarEntry(theentry);
+ try
+ {
+ JarEntry entry = theJar.getJarEntry( theentry );
- if (entry != null) {
- data = theJar.getInputStream(entry);
+ if ( entry != null )
+ {
+ data = theJar.getInputStream( entry );
}
- } catch (Exception fnfe) {
- throw new ResourceNotFoundException(fnfe.getMessage());
+ }
+ catch ( Exception fnfe )
+ {
+ throw new ResourceNotFoundException( fnfe.getMessage() );
}
return data;
}
- public Hashtable<String, String> getEntries() {
- Hashtable<String, String> allEntries = new Hashtable<>(559);
+ public Hashtable getEntries()
+ {
+ Hashtable<String, String> allEntries = new Hashtable<String, String>( 559 );
- if (theJar != null) {
+ if ( theJar != null )
+ {
Enumeration<JarEntry> all = theJar.entries();
- while (all.hasMoreElements()) {
- JarEntry je = all.nextElement();
+ while ( all.hasMoreElements() )
+ {
+ JarEntry je = (JarEntry) all.nextElement();
// We don't map plain directory entries
- if (!je.isDirectory()) {
- allEntries.put(je.getName(), this.urlpath);
+ if ( !je.isDirectory() )
+ {
+ allEntries.put( je.getName(), this.urlpath );
}
}
}
return allEntries;
}
- public String getUrlPath() {
+ public String getUrlPath()
+ {
return urlpath;
}
- public PlexusResource getPlexusResource(final String name) {
- final JarEntry entry = theJar.getJarEntry(name);
- if (entry == null) {
+ public PlexusResource getPlexusResource( final String name )
+ {
+ final JarEntry entry = theJar.getJarEntry( name );
+ if ( entry == null )
+ {
return null;
}
- return new PlexusResource() {
- @Override
- public File getFile() {
+ return new PlexusResource()
+ {
+ public File getFile()
+ throws IOException
+ {
return null;
}
- @Override
- public InputStream getInputStream() throws IOException {
- return theJar.getInputStream(entry);
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return theJar.getInputStream( entry );
}
- @Override
- public String getName() {
+ public String getName()
+ {
return conn.getURL() + name;
}
- @Override
- public URI getURI() {
+ public URI getURI()
+ throws IOException
+ {
return null;
}
- @Override
- public URL getURL() throws IOException {
- return new URL(conn.getJarFileURL(), name);
+ public URL getURL()
+ throws IOException
+ {
+ return new URL( conn.getJarFileURL(), name );
}
};
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/JarResourceLoader.java
=====================================
@@ -1,5 +1,7 @@
package org.codehaus.plexus.resource.loader;
+import org.codehaus.plexus.component.annotations.Component;
+
/*
* The MIT License
*
@@ -24,70 +26,93 @@ package org.codehaus.plexus.resource.loader;
* SOFTWARE.
*/
-import javax.inject.Named;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.resource.PlexusResource;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.codehaus.plexus.resource.PlexusResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* @author Jason van Zyl
*/
- at Named(JarResourceLoader.ID)
-public class JarResourceLoader extends AbstractResourceLoader {
- private static final Logger LOGGER = LoggerFactory.getLogger(JarResourceLoader.class);
-
+ at Component( role = ResourceLoader.class, hint = "jar", instantiationStrategy = "per-lookup" )
+public class JarResourceLoader
+ extends AbstractResourceLoader
+{
public static final String ID = "jar";
/**
* Maps entries to the parent JAR File (key = the entry *excluding* plain directories, value = the JAR URL).
*/
- private final Map<String, String> entryDirectory = new LinkedHashMap<>(559);
+ private Map entryDirectory = new LinkedHashMap( 559 );
/**
* Maps JAR URLs to the actual JAR (key = the JAR URL, value = the JAR).
*/
- private final Map<String, JarHolder> jarFiles = new LinkedHashMap<>(89);
+ private Map<String, JarHolder> jarfiles = new LinkedHashMap<String, JarHolder>( 89 );
+
+ private boolean initializeCalled;
+
+ public void initialize()
+ throws InitializationException
+ {
+ initializeCalled = true;
+
+ if ( paths != null )
+ {
+ for ( int i = 0; i < paths.size(); i++ )
+ {
+ loadJar( (String) paths.get( i ) );
+ }
+ }
+ }
- private void loadJar(String path) {
- LOGGER.debug("JarResourceLoader : trying to load '{}'", path);
+ private void loadJar( String path )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "JarResourceLoader : trying to load \"" + path + "\"" );
+ }
// Check path information
- if (path == null) {
- LOGGER.error("JarResourceLoader : can not load JAR - JAR path is null");
+ if ( path == null )
+ {
+ getLogger().error( "JarResourceLoader : can not load JAR - JAR path is null" );
return;
}
- if (!path.startsWith("jar:")) {
- LOGGER.error("JarResourceLoader : JAR path must start with jar: -> "
- + "see java.net.JarURLConnection for information");
+ if ( !path.startsWith( "jar:" ) )
+ {
+ getLogger().error(
+ "JarResourceLoader : JAR path must start with jar: -> "
+ + "see java.net.JarURLConnection for information" );
return;
}
- if (!path.endsWith("!/")) {
+ if ( !path.endsWith( "!/" ) )
+ {
path += "!/";
}
// Close the jar if it's already open this is useful for a reload
- closeJar(path);
+ closeJar( path );
// Create a new JarHolder
- JarHolder temp = new JarHolder(path);
+ JarHolder temp = new JarHolder( path );
// Add it's entries to the entryCollection
- addEntries(temp.getEntries());
+ addEntries( temp.getEntries() );
// Add it to the Jar table
- jarFiles.put(temp.getUrlPath(), temp);
+ jarfiles.put( temp.getUrlPath(), temp );
}
/**
* Closes a Jar file and set its URLConnection to null.
*/
- private void closeJar(String path) {
- if (jarFiles.containsKey(path)) {
- JarHolder theJar = jarFiles.get(path);
+ private void closeJar( String path )
+ {
+ if ( jarfiles.containsKey( path ) )
+ {
+ JarHolder theJar = (JarHolder) jarfiles.get( path );
theJar.close();
}
@@ -96,47 +121,69 @@ public class JarResourceLoader extends AbstractResourceLoader {
/**
* Copy all the entries into the entryDirectory. It will overwrite any duplicate keys.
*/
- private void addEntries(Map<String, String> entries) {
- entryDirectory.putAll(entries);
+ private void addEntries( Map entries )
+ {
+ entryDirectory.putAll( entries );
}
/**
- * Get an {@link PlexusResource} by name.
- *
- * @param source name of resource to get
- * @return PlexusResource containing the resource
- * @throws ResourceNotFoundException if resource not found.
+ * Get an InputStream so that the Runtime can build a template with it.
+ *
+ * @param source name of template to get
+ * @return InputStream containing the template
+ * @throws ResourceNotFoundException if template not found in the file template path.
*/
- @Override
- public PlexusResource getResource(String source) throws ResourceNotFoundException {
- if (source == null || source.length() == 0) {
- throw new ResourceNotFoundException("Need to have a resource!");
+ public PlexusResource getResource( String source )
+ throws ResourceNotFoundException
+ {
+ if ( !initializeCalled )
+ {
+ try
+ {
+ initialize();
+ }
+ catch ( InitializationException e )
+ {
+ throw new ResourceNotFoundException( e.getMessage(), e );
+ }
+ }
+
+ if ( source == null || source.length() == 0 )
+ {
+ throw new ResourceNotFoundException( "Need to have a resource!" );
}
/*
* if a / leads off, then just nip that :)
*/
- if (source.startsWith("/")) {
- source = source.substring(1);
+ if ( source.startsWith( "/" ) )
+ {
+ source = source.substring( 1 );
}
- if (entryDirectory.containsKey(source)) {
- String jarurl = entryDirectory.get(source);
+ if ( entryDirectory.containsKey( source ) )
+ {
+ String jarurl = (String) entryDirectory.get( source );
- final JarHolder holder = jarFiles.get(jarurl);
- if (holder != null) {
- return holder.getPlexusResource(source);
+ final JarHolder holder = (JarHolder) jarfiles.get( jarurl );
+ if ( holder != null )
+ {
+ return holder.getPlexusResource( source );
}
}
- throw new ResourceNotFoundException("JarResourceLoader Error: cannot find resource " + source);
+ throw new ResourceNotFoundException( "JarResourceLoader Error: cannot find resource " + source );
}
- @Override
- public void addSearchPath(String path) {
- if (!paths.contains(path)) {
- loadJar(path);
- paths.add(path);
+ public void addSearchPath( String path )
+ {
+ if ( !paths.contains( path ) )
+ {
+ if ( initializeCalled )
+ {
+ loadJar( path );
+ }
+ paths.add( path );
}
}
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/ResourceIOException.java
=====================================
@@ -29,14 +29,18 @@ package org.codehaus.plexus.resource.loader;
* {@link ResourceLoader} encounters an {@link java.io.IOException}, which indicates that the resource exists, but
* wasn't accessible.
*/
-public class ResourceIOException extends ResourceNotFoundException {
+public class ResourceIOException
+ extends ResourceNotFoundException
+{
private static final long serialVersionUID = 1342518075415496931L;
- public ResourceIOException(String name, Throwable cause) {
- super(name, cause);
+ public ResourceIOException( String name, Throwable cause )
+ {
+ super( name, cause );
}
- public ResourceIOException(String name) {
- super(name);
+ public ResourceIOException( String name )
+ {
+ super( name );
}
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/ResourceLoader.java
=====================================
@@ -32,21 +32,25 @@ import org.codehaus.plexus.resource.PlexusResource;
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @version $Id$
*/
-public interface ResourceLoader {
+public interface ResourceLoader
+{
+ String ROLE = ResourceLoader.class.getName();
+
/**
* @deprecated Use {@link #getResource(String)}.
*/
- @Deprecated
- InputStream getResourceAsInputStream(String name) throws ResourceNotFoundException;
+ InputStream getResourceAsInputStream( String name )
+ throws ResourceNotFoundException;
- void addSearchPath(String path);
+ void addSearchPath( String path );
/**
* Returns the resource with the given name.
- *
+ *
* @param name The resources name.
* @return The resource with the given name.
* @throws ResourceNotFoundException The resource wasn't found, or wasn't available.
*/
- PlexusResource getResource(String name) throws ResourceNotFoundException;
+ PlexusResource getResource( String name )
+ throws ResourceNotFoundException;
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/ResourceNotFoundException.java
=====================================
@@ -28,14 +28,18 @@ package org.codehaus.plexus.resource.loader;
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @version $Id$
*/
-public class ResourceNotFoundException extends Exception {
+public class ResourceNotFoundException
+ extends Exception
+{
private static final long serialVersionUID = -566548849252110330L;
- public ResourceNotFoundException(String name) {
- super("Could not find resource '" + name + "'.");
+ public ResourceNotFoundException( String name )
+ {
+ super( "Could not find resource '" + name + "'." );
}
- public ResourceNotFoundException(String name, Throwable cause) {
- super("Could not find resource '" + name + "'.", cause);
+ public ResourceNotFoundException( String name, Throwable cause )
+ {
+ super( "Could not find resource '" + name + "'.", cause );
}
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoader.java
=====================================
@@ -24,43 +24,49 @@ package org.codehaus.plexus.resource.loader;
* SOFTWARE.
*/
-import javax.inject.Named;
-import javax.inject.Singleton;
-
import java.net.URL;
+import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.resource.PlexusResource;
+import org.codehaus.plexus.resource.loader.AbstractResourceLoader;
+import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
/**
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @version $Id$
*/
- at Named(ThreadContextClasspathResourceLoader.ID)
- at Singleton
-public class ThreadContextClasspathResourceLoader extends AbstractResourceLoader {
+ at Component( role = ResourceLoader.class, hint = "classloader" )
+public class ThreadContextClasspathResourceLoader
+ extends AbstractResourceLoader
+{
+
public static final String ID = "classloader";
// ----------------------------------------------------------------------
// ResourceLoader Implementation
// ----------------------------------------------------------------------
- @Override
- public PlexusResource getResource(String name) throws ResourceNotFoundException {
+ public PlexusResource getResource( String name )
+ throws ResourceNotFoundException
+ {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if (classLoader == null) {
- throw new ResourceNotFoundException(name);
+ if ( classLoader == null )
+ {
+ throw new ResourceNotFoundException( name );
}
- if (name != null && name.startsWith("/")) {
- name = name.substring(1);
+ if ( name != null && name.startsWith( "/" ) )
+ {
+ name = name.substring( 1 );
}
- final URL url = classLoader.getResource(name);
- if (url == null) {
- throw new ResourceNotFoundException(name);
+ final URL url = classLoader.getResource( name );
+ if ( url == null )
+ {
+ throw new ResourceNotFoundException( name );
}
- return new URLPlexusResource(url);
+ return new URLPlexusResource( url );
}
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/URLPlexusResource.java
=====================================
@@ -35,35 +35,42 @@ import org.codehaus.plexus.resource.PlexusResource;
/**
* Implementation of {@link PlexusResource} for URL's.
*/
-public class URLPlexusResource implements PlexusResource {
+public class URLPlexusResource
+ implements PlexusResource
+{
private final URL url;
- public URLPlexusResource(URL url) {
+ public URLPlexusResource( URL url )
+ {
this.url = url;
}
- @Override
- public File getFile() {
+ public File getFile()
+ throws IOException
+ {
return null;
}
- @Override
- public InputStream getInputStream() throws IOException {
+ public InputStream getInputStream()
+ throws IOException
+ {
return url.openStream();
}
- @Override
- public String getName() {
+ public String getName()
+ {
return url.toExternalForm();
}
- @Override
- public URI getURI() {
+ public URI getURI()
+ throws IOException
+ {
return null;
}
- @Override
- public URL getURL() {
+ public URL getURL()
+ throws IOException
+ {
return url;
}
}
=====================================
src/main/java/org/codehaus/plexus/resource/loader/URLResourceLoader.java
=====================================
@@ -24,8 +24,6 @@ package org.codehaus.plexus.resource.loader;
* SOFTWARE.
*/
-import javax.inject.Named;
-
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -33,51 +31,63 @@ import java.net.URL;
import java.util.HashMap;
import java.util.Map;
+import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.resource.PlexusResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* @author Jason van Zyl
*/
- at Named(URLResourceLoader.ID)
-public class URLResourceLoader extends AbstractResourceLoader {
- private static final Logger LOGGER = LoggerFactory.getLogger(URLResourceLoader.class);
+ at Component( role = ResourceLoader.class, hint = "url", instantiationStrategy = "per-lookup" )
+public class URLResourceLoader
+ extends AbstractResourceLoader
+{
public static final String ID = "url";
- protected Map<String, String> templateRoots = new HashMap<>();
+ protected Map<String, String> templateRoots = new HashMap<String, String>();
/**
- * Get an {@link PlexusResource} with given name.
- *
- * @param name name of resource to fetch byte stream of.
- * @return PlexusResource containing the resource.
- * @throws ResourceNotFoundException if resource not found.
+ * Get an InputStream so that the Runtime can build a template with it.
+ *
+ * @param name name of template to fetch bytestream of
+ * @return InputStream containing the template
+ * @throws ResourceNotFoundException if template not found in the file template path.
*/
- @Override
- public PlexusResource getResource(String name) throws ResourceNotFoundException {
- if (name == null || name.length() == 0) {
- throw new ResourceNotFoundException("URLResourceLoader : No template name provided");
+ public PlexusResource getResource( String name )
+ throws ResourceNotFoundException
+ {
+ if ( name == null || name.length() == 0 )
+ {
+ throw new ResourceNotFoundException( "URLResourceLoader : No template name provided" );
}
- for (String path : paths) {
- try {
- URL u = new URL(path + name);
+ for ( String path : paths )
+ {
+ try
+ {
+ URL u = new URL( path + name );
final InputStream inputStream = u.openStream();
- if (inputStream != null) {
- LOGGER.debug("URLResourceLoader: Found '{}' at '{}'", name, path);
+ if ( inputStream != null )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "URLResourceLoader: Found '" + name + "' at '" + path + "'" );
+ }
// save this root for later re-use
- templateRoots.put(name, path);
+ templateRoots.put( name, path );
- return new URLPlexusResource(u) {
+ return new URLPlexusResource( u )
+ {
private boolean useSuper;
- public synchronized InputStream getInputStream() throws IOException {
- if (!useSuper) {
+ public synchronized InputStream getInputStream()
+ throws IOException
+ {
+ if ( !useSuper )
+ {
useSuper = true;
return inputStream;
}
@@ -85,25 +95,43 @@ public class URLResourceLoader extends AbstractResourceLoader {
}
};
}
- } catch (MalformedURLException mue) {
- LOGGER.debug("URLResourceLoader: No valid URL '{}{}'", path, name);
- } catch (IOException ioe) {
- LOGGER.debug("URLResourceLoader: Exception when looking for '{}' at '{}'", name, path, ioe);
+ }
+ catch( MalformedURLException mue )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "URLResourceLoader: No valid URL '" + path + name + '\'' );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug(
+ "URLResourceLoader: Exception when looking for '" + name + "' at '" + path + "'",
+ ioe );
+ }
}
}
-
+
// here we try to download without any path just the name which can be an url
- try {
- URL u = new URL(name);
+ try
+ {
+ URL u = new URL( name );
final InputStream inputStream = u.openStream();
- if (inputStream != null) {
- return new URLPlexusResource(u) {
+ if ( inputStream != null )
+ {
+ return new URLPlexusResource( u )
+ {
private boolean useSuper;
- public synchronized InputStream getInputStream() throws IOException {
- if (!useSuper) {
+ public synchronized InputStream getInputStream()
+ throws IOException
+ {
+ if ( !useSuper )
+ {
useSuper = true;
return inputStream;
}
@@ -111,13 +139,23 @@ public class URLResourceLoader extends AbstractResourceLoader {
}
};
}
- } catch (MalformedURLException mue) {
- LOGGER.debug("URLResourceLoader: No valid URL '{}'", name);
- } catch (IOException ioe) {
- LOGGER.debug("URLResourceLoader: Exception when looking for '{}'", name, ioe);
}
+ catch( MalformedURLException mue )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "URLResourceLoader: No valid URL '" + name + '\'' );
+ }
+ }
+ catch ( IOException ioe )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "URLResourceLoader: Exception when looking for '" + name + '\'', ioe );
+ }
+ }
// convert to a general Velocity ResourceNotFoundException
- throw new ResourceNotFoundException(name);
+ throw new ResourceNotFoundException( name );
}
}
=====================================
src/test/java/org/codehaus/plexus/resource/ResourceManagerTest.java
=====================================
@@ -24,94 +24,95 @@ package org.codehaus.plexus.resource;
* SOFTWARE.
*/
-import javax.inject.Inject;
-
import java.io.File;
import java.io.InputStream;
-import org.codehaus.plexus.testing.PlexusTest;
-import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.IOUtil;
-import org.junit.jupiter.api.Test;
-
-import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.codehaus.plexus.util.FileUtils;
/**
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @version $Id$
*/
- at PlexusTest
-class ResourceManagerTest {
- @Inject
- private ResourceManager resourceManager;
+public class ResourceManagerTest
+ extends PlexusTestCase
+{
+
+ public void testResourceManagerRetrievingInputStreams()
+ throws Exception
+ {
+ ResourceManager resourceManager = (ResourceManager) lookup( ResourceManager.ROLE );
- @Test
- void testResourceManagerRetrievingInputStreams() throws Exception {
InputStream in;
- File absoluteFile = new File(getBasedir(), "src/test/file-resources/dir/file.txt").getAbsoluteFile();
- assertTrue(absoluteFile.isFile());
- assertTrue(absoluteFile.isAbsolute());
- in = resourceManager.getResourceAsInputStream(absoluteFile.getAbsolutePath());
- assertEquals("file.txt", IOUtil.toString(in, "UTF-8"));
+ File absoluteFile = new File( getBasedir(), "src/test/file-resources/dir/file.txt" ).getAbsoluteFile();
+ assertTrue( absoluteFile.isFile() );
+ assertTrue( absoluteFile.isAbsolute() );
+ in = resourceManager.getResourceAsInputStream( absoluteFile.getAbsolutePath() );
+ assertEquals( "file.txt", IOUtil.toString( in, "UTF-8" ) );
- in = resourceManager.getResourceAsInputStream("/dir/file.txt");
- assertEquals("file.txt", IOUtil.toString(in, "UTF-8"));
+ in = resourceManager.getResourceAsInputStream( "/dir/file.txt" );
+ assertEquals( "file.txt", IOUtil.toString( in, "UTF-8" ) );
- in = resourceManager.getResourceAsInputStream("dir/file.txt");
- assertEquals("file.txt", IOUtil.toString(in, "UTF-8"));
+ in = resourceManager.getResourceAsInputStream( "dir/file.txt" );
+ assertEquals( "file.txt", IOUtil.toString( in, "UTF-8" ) );
- in = resourceManager.getResourceAsInputStream("/dir/classpath.txt");
- assertEquals("classpath.txt", IOUtil.toString(in, "UTF-8"));
+ in = resourceManager.getResourceAsInputStream( "/dir/classpath.txt" );
+ assertEquals( "classpath.txt", IOUtil.toString( in, "UTF-8" ) );
- in = resourceManager.getResourceAsInputStream("dir/classpath.txt");
- assertEquals("classpath.txt", IOUtil.toString(in, "UTF-8"));
+ in = resourceManager.getResourceAsInputStream( "dir/classpath.txt" );
+ assertEquals( "classpath.txt", IOUtil.toString( in, "UTF-8" ) );
}
- @Test
- void testResourceManagerRetrievingFiles() throws Exception {
+ public void testResourceManagerRetrievingFiles()
+ throws Exception
+ {
+ ResourceManager resourceManager = (ResourceManager) lookup( ResourceManager.ROLE );
+
File f;
- File absoluteFile = new File(getBasedir(), "src/test/file-resources/dir/file.txt").getAbsoluteFile();
- assertTrue(absoluteFile.isFile());
- assertTrue(absoluteFile.isAbsolute());
- f = resourceManager.getResourceAsFile(absoluteFile.getAbsolutePath());
- assertEquals("file.txt", FileUtils.fileRead(f, "UTF-8"));
+ File absoluteFile = new File( getBasedir(), "src/test/file-resources/dir/file.txt" ).getAbsoluteFile();
+ assertTrue( absoluteFile.isFile() );
+ assertTrue( absoluteFile.isAbsolute() );
+ f = resourceManager.getResourceAsFile( absoluteFile.getAbsolutePath() );
+ assertEquals( "file.txt", FileUtils.fileRead( f, "UTF-8" ) );
- f = resourceManager.getResourceAsFile("/dir/file.txt");
- assertEquals("file.txt", FileUtils.fileRead(f, "UTF-8"));
+ f = resourceManager.getResourceAsFile( "/dir/file.txt" );
+ assertEquals( "file.txt", FileUtils.fileRead( f, "UTF-8" ) );
- f = resourceManager.getResourceAsFile("dir/file.txt");
- assertEquals("file.txt", FileUtils.fileRead(f, "UTF-8"));
+ f = resourceManager.getResourceAsFile( "dir/file.txt" );
+ assertEquals( "file.txt", FileUtils.fileRead( f, "UTF-8" ) );
- f = resourceManager.getResourceAsFile("/dir/classpath.txt");
- assertEquals("classpath.txt", FileUtils.fileRead(f, "UTF-8"));
+ f = resourceManager.getResourceAsFile( "/dir/classpath.txt" );
+ assertEquals( "classpath.txt", FileUtils.fileRead( f, "UTF-8" ) );
- f = resourceManager.getResourceAsFile("dir/classpath.txt");
- assertEquals("classpath.txt", FileUtils.fileRead(f, "UTF-8"));
+ f = resourceManager.getResourceAsFile( "dir/classpath.txt" );
+ assertEquals( "classpath.txt", FileUtils.fileRead( f, "UTF-8" ) );
}
- @Test
- void testResourceManagerRetrievingFilesToSpecificLocation() throws Exception {
- File outDir = new File(getBasedir(), "target/test/unit/output-directory");
-
- resourceManager.setOutputDirectory(outDir);
-
- File ef = new File(outDir, "test/f.txt");
- FileUtils.forceDelete(ef);
- assertFalse(ef.exists());
- File f = resourceManager.getResourceAsFile("dir/file.txt", "test/f.txt");
- assertEquals("file.txt", FileUtils.fileRead(f, "UTF-8"));
- assertEquals(ef, f);
-
- File ec = new File(outDir, "test/c.txt");
- FileUtils.forceDelete(ec);
- assertFalse(ec.exists());
- File c = resourceManager.getResourceAsFile("dir/classpath.txt", "test/c.txt");
- assertEquals("classpath.txt", FileUtils.fileRead(c, "UTF-8"));
- assertEquals(ec, c);
+ public void testResourceManagerRetrievingFilesToSpecificLocation()
+ throws Exception
+ {
+ File outDir = new File( getBasedir(), "target/test/unit/output-directory" );
+
+ ResourceManager resourceManager = (ResourceManager) lookup( ResourceManager.ROLE );
+
+ resourceManager.setOutputDirectory( outDir );
+
+ File ef = new File( outDir, "test/f.txt" );
+ FileUtils.forceDelete( ef );
+ assertFalse( ef.exists() );
+ File f = resourceManager.getResourceAsFile( "dir/file.txt", "test/f.txt" );
+ assertEquals( "file.txt", FileUtils.fileRead( f, "UTF-8" ) );
+ assertEquals( ef, f );
+
+ File ec = new File( outDir, "test/c.txt" );
+ FileUtils.forceDelete( ec );
+ assertFalse( ec.exists() );
+ File c = resourceManager.getResourceAsFile( "dir/classpath.txt", "test/c.txt" );
+ assertEquals( "classpath.txt", FileUtils.fileRead( c, "UTF-8" ) );
+ assertEquals( ec, c );
}
+
}
=====================================
src/test/java/org/codehaus/plexus/resource/loader/AbstractResourceLoaderTest.java
=====================================
@@ -24,44 +24,50 @@ package org.codehaus.plexus.resource.loader;
* SOFTWARE.
*/
-import javax.inject.Inject;
-
import java.io.InputStream;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.resource.loader.ResourceLoader;
+import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.util.IOUtil;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
-
/**
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @version $Id$
*/
-public abstract class AbstractResourceLoaderTest {
- @Inject
- protected ResourceLoader resourceLoader;
-
- protected void assertResource(String name, String expectedContent) throws Exception {
+public abstract class AbstractResourceLoaderTest
+ extends PlexusTestCase
+{
+ protected void assertResource( String name, String expectedContent )
+ throws Exception
+ {
+ ResourceLoader resourceLoader = (ResourceLoader) lookup( ResourceLoader.ROLE );
- InputStream is = resourceLoader.getResource(name).getInputStream();
+ InputStream is = resourceLoader.getResource( name ).getInputStream();
- assertNotNull(is, "The returned input stream is null, name: '" + name + "'.");
+ assertNotNull( "The returned input stream is null, name: '" + name + "'.", is );
- String actualContent = IOUtil.toString(is, "UTF-8");
+ String actualContent = IOUtil.toString( is, "UTF-8" );
- assertEquals(expectedContent, actualContent);
+ assertEquals( expectedContent, actualContent );
}
- protected void assertMissingResource(String name) throws Exception {
- try {
- InputStream is = resourceLoader.getResource(name).getInputStream();
+ protected void assertMissingResource( String name )
+ throws Exception
+ {
+ ResourceLoader resourceLoader = (ResourceLoader) lookup( ResourceLoader.ROLE );
- String content = IOUtil.toString(is, "UTF-8");
+ try
+ {
+ InputStream is = resourceLoader.getResource( name ).getInputStream();
- fail("Expected ResourceNotFoundException while looking for a resource named '" + name + "'. Content:\n"
- + content);
- } catch (ResourceNotFoundException e) {
+ String content = IOUtil.toString( is, "UTF-8" );
+
+ fail( "Expected ResourceNotFoundException while looking for a resource named '" + name + "'. Content:\n"
+ + content );
+ }
+ catch ( ResourceNotFoundException e )
+ {
// expected
}
}
=====================================
src/test/java/org/codehaus/plexus/resource/loader/FileResourceLoaderTest.java
=====================================
@@ -27,41 +27,44 @@ package org.codehaus.plexus.resource.loader;
import java.io.File;
import org.codehaus.plexus.resource.PlexusResource;
-import org.codehaus.plexus.testing.PlexusTest;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.codehaus.plexus.resource.loader.AbstractResourceLoaderTest;
/**
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @version $Id$
*/
- at PlexusTest
-class FileResourceLoaderTest extends AbstractResourceLoaderTest {
- @Test
- void testLookupWithAAbsolutePathName() throws Exception {
- assertResource("/dir/file.txt", "file.txt");
+public class FileResourceLoaderTest
+ extends AbstractResourceLoaderTest
+{
+ public void testLookupWithAAbsolutePathName()
+ throws Exception
+ {
+ assertResource( "/dir/file.txt", "file.txt" );
}
- @Test
- void testLookupWithARelativePath() throws Exception {
- assertResource("dir/file.txt", "file.txt");
+ public void testLookupWithARelativePath()
+ throws Exception
+ {
+ assertResource( "dir/file.txt", "file.txt" );
}
- @Test
- void testLookupWhenTheResourceIsMissing() throws Exception {
- assertMissingResource("/foo.txt");
+ public void testLookupWhenTheResourceIsMissing()
+ throws Exception
+ {
+ assertMissingResource( "/foo.txt" );
- assertMissingResource("foo.txt");
+ assertMissingResource( "foo.txt" );
}
- @Test
- void testPlexusResource() throws Exception {
- PlexusResource resource = resourceLoader.getResource("/dir/file.txt");
- final File f = new File("src/test/file-resources", "/dir/file.txt");
- assertEquals(f.getAbsolutePath(), resource.getFile().getPath());
- assertEquals(f.toURI(), resource.getURI());
- assertEquals(f.toURI().toURL(), resource.getURL());
- assertEquals(f.getAbsolutePath(), resource.getName());
+ public void testPlexusResource()
+ throws Exception
+ {
+ ResourceLoader resourceLoader = (ResourceLoader) lookup( ResourceLoader.ROLE );
+ PlexusResource resource = resourceLoader.getResource( "/dir/file.txt" );
+ final File f = new File( "src/test/file-resources", "/dir/file.txt" );
+ assertEquals( f.getAbsolutePath(), resource.getFile().getPath() );
+ assertEquals( f.toURI(), resource.getURI() );
+ assertEquals( f.toURI().toURL(), resource.getURL() );
+ assertEquals( f.getAbsolutePath(), resource.getName() );
}
}
=====================================
src/test/java/org/codehaus/plexus/resource/loader/ThreadContextClasspathResourceLoaderTest.java
=====================================
@@ -27,57 +27,57 @@ package org.codehaus.plexus.resource.loader;
import java.net.URL;
import org.codehaus.plexus.resource.PlexusResource;
-import org.codehaus.plexus.testing.PlexusTest;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
/**
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @version $Id$
*/
- at PlexusTest
-class ThreadContextClasspathResourceLoaderTest extends AbstractResourceLoaderTest {
- @Test
- void testLookupWithAAbsolutePathName() throws Exception {
- assertResource("/dir/classpath.txt", "classpath.txt");
+public class ThreadContextClasspathResourceLoaderTest
+ extends AbstractResourceLoaderTest
+{
+ public void testLookupWithAAbsolutePathName()
+ throws Exception
+ {
+ assertResource( "/dir/classpath.txt", "classpath.txt" );
}
- @Test
- void testLookupWithARelativePath() throws Exception {
- assertResource("dir/classpath.txt", "classpath.txt");
+ public void testLookupWithARelativePath()
+ throws Exception
+ {
+ assertResource( "dir/classpath.txt", "classpath.txt" );
}
- @Test
- void testLookupWhenTheResourceIsMissing() throws Exception {
- assertMissingResource("/foo.txt");
+ public void testLookupWhenTheResourceIsMissing()
+ throws Exception
+ {
+ assertMissingResource( "/foo.txt" );
- assertMissingResource("foo.txt");
+ assertMissingResource( "foo.txt" );
}
- @Test
- void testLookupWithANullThreadContextClassLoader() throws Exception {
+ public void testLookupWithANullThreadContextClassLoader()
+ throws Exception
+ {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(null);
+ Thread.currentThread().setContextClassLoader( null );
- assertMissingResource("/dir/classpath.txt");
+ assertMissingResource( "/dir/classpath.txt" );
- assertMissingResource("dir/classpath.txt");
+ assertMissingResource( "dir/classpath.txt" );
- Thread.currentThread().setContextClassLoader(loader);
+ Thread.currentThread().setContextClassLoader( loader );
}
- @Test
- void testPlexusResource() throws Exception {
- PlexusResource resource = resourceLoader.getResource("/dir/classpath.txt");
- assertNull(resource.getFile());
- assertNull(resource.getURI());
- URL url = Thread.currentThread().getContextClassLoader().getResource("dir/classpath.txt");
- assertNotNull(url);
- assertEquals(url, resource.getURL());
- assertEquals(url.toExternalForm(), resource.getName());
+ public void testPlexusResource()
+ throws Exception
+ {
+ ResourceLoader resourceLoader = (ResourceLoader) lookup( ResourceLoader.ROLE );
+ PlexusResource resource = resourceLoader.getResource( "/dir/classpath.txt" );
+ assertNull( resource.getFile() );
+ assertNull( resource.getURI() );
+ URL url = Thread.currentThread().getContextClassLoader().getResource( "/dir/classpath.txt" );
+ assertEquals( url, resource.getURL() );
+ assertEquals( url.toExternalForm(), resource.getName() );
}
}
=====================================
src/test/java/org/codehaus/plexus/resource/loader/URLResourceLoaderTest.java
=====================================
@@ -1,34 +1,48 @@
package org.codehaus.plexus.resource.loader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.slf4j.Logger;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import junit.framework.TestCase;
+
+import org.codehaus.plexus.logging.Logger;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
- at ExtendWith(MockitoExtension.class)
-class URLResourceLoaderTest {
+public class URLResourceLoaderTest
+ extends TestCase
+{
@Mock
private Logger logger;
@InjectMocks
private ResourceLoader resourceLoader = new URLResourceLoader();
- @Test
- void testMalformedURL() {
- try {
- resourceLoader.getResource("LICENSE.txt");
+ @Override
+ protected void setUp()
+ throws Exception
+ {
+ MockitoAnnotations.initMocks( this );
+ }
+
+ public void testMalformedURL()
+ throws Exception
+ {
+ when( logger.isDebugEnabled() ).thenReturn( true );
+
+ try
+ {
+ resourceLoader.getResource( "LICENSE.txt" );
fail();
- } catch (ResourceNotFoundException e) {
- verify(logger).debug("URLResourceLoader: No valid URL '{}'", "LICENSE.txt");
- verifyNoMoreInteractions(logger);
- assertEquals("Could not find resource 'LICENSE.txt'.", e.getMessage());
}
+ catch ( ResourceNotFoundException e )
+ {
+ verify( logger ).isDebugEnabled();
+ verify( logger ).debug( "URLResourceLoader: No valid URL 'LICENSE.txt'" );
+ verifyNoMoreInteractions( logger );
+ assertEquals( "Could not find resource 'LICENSE.txt'.", e.getMessage() );
+ }
+
}
}
=====================================
src/test/java/org/codehaus/plexus/resource/loader/manager/ResourceManagerTest.java
=====================================
@@ -24,25 +24,19 @@ package org.codehaus.plexus.resource.loader.manager;
* SOFTWARE.
*/
-import javax.inject.Inject;
-
+import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.resource.ResourceManager;
-import org.codehaus.plexus.testing.PlexusTest;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author <a href="mailto:trygvis at inamo.no">Trygve Laugstøl</a>
* @version $Id$
*/
- at PlexusTest
-class ResourceManagerTest {
- @Inject
- private ResourceManager resourceManager;
-
- @Test
- void testFoo() {
- assertNotNull(resourceManager);
+public class ResourceManagerTest
+ extends PlexusTestCase
+{
+ public void testFoo()
+ throws Exception
+ {
+ lookup( ResourceManager.ROLE );
}
}
View it on GitLab: https://salsa.debian.org/java-team/plexus-resources/-/commit/6a2b16506e6e4587158d647d39c508f4f20b8271
--
View it on GitLab: https://salsa.debian.org/java-team/plexus-resources/-/commit/6a2b16506e6e4587158d647d39c508f4f20b8271
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20250412/3c31756b/attachment.htm>
More information about the pkg-java-commits
mailing list