Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update parent pom to 15 #86

Merged
merged 4 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-components</artifactId>
<version>10.0</version>
<artifactId>plexus</artifactId>
<version>15</version>
<relativePath />
</parent>

<artifactId>plexus-resources</artifactId>
Expand All @@ -17,8 +18,8 @@
<scm>
<connection>scm:git:[email protected]:codehaus-plexus/plexus-resources.git</connection>
<developerConnection>scm:git:[email protected]:codehaus-plexus/plexus-resources.git</developerConnection>
<url>http://github.com/codehaus-plexus/plexus-resources</url>
<tag>plexus-resources-1.2.0</tag>
<url>http://github.com/codehaus-plexus/plexus-resources</url>
</scm>
<issueManagement>
<system>jira</system>
Expand All @@ -36,11 +37,25 @@
<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>
<artifactId>plexus-utils</artifactId>
</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>
Expand All @@ -51,12 +66,11 @@
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>

<!-- TEST -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -98,42 +112,24 @@
<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>
<phase>site-deploy</phase><!-- deploy site with maven-scm-publish-plugin -->
<!-- deploy site with maven-scm-publish-plugin -->
<goals>
<goal>publish-scm</goal>
</goals>
<phase>site-deploy</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<version>0.3.5</version>
<executions>
<execution>
<goals>
<goal>main-index</goal>
<goal>test-index</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.5</version>
</plugin>
</plugins>
</reporting>

</project>
186 changes: 71 additions & 115 deletions src/main/java/org/codehaus/plexus/resource/DefaultResourceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
* 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.resource.loader.FileResourceCreationException;
import org.codehaus.plexus.resource.loader.ResourceIOException;
Expand All @@ -34,32 +43,21 @@
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;
import javax.inject.Inject;
import javax.inject.Named;

/**
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
* @author Jason van Zyl
* @version $Id$
*/
@Named
public class DefaultResourceManager implements ResourceManager
{
private static final Logger LOGGER = LoggerFactory.getLogger( DefaultResourceManager.class );
public class DefaultResourceManager implements ResourceManager {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultResourceManager.class);

private final Map<String, ResourceLoader> resourceLoaders;

private File outputDirectory;

@Inject
public DefaultResourceManager( Map<String, ResourceLoader> resourceLoaders )
{
public DefaultResourceManager(Map<String, ResourceLoader> resourceLoaders) {
this.resourceLoaders = resourceLoaders;
}

Expand All @@ -68,173 +66,131 @@ public DefaultResourceManager( Map<String, ResourceLoader> resourceLoaders )
// ----------------------------------------------------------------------

@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) {
// 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) {
// 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 = 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() );
LOGGER.debug("The resource '{}' was found as '{}'", name, resource.getName());

return resource;
}
catch ( ResourceNotFoundException e )
{
LOGGER.debug( "The resource '{}' was not found with resourceLoader '{}'",
name, resourceLoader.getClass().getName() );
} catch (ResourceNotFoundException e) {
LOGGER.debug(
"The resource '{}' was not found with resourceLoader '{}'",
name,
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);
}
}

}
Loading