Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Dec 10, 2023
1 parent 441117b commit 512f188
Show file tree
Hide file tree
Showing 22 changed files with 442 additions and 679 deletions.
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<scm>
<connection>scm:git:git@github.com:codehaus-plexus/plexus-resources.git</connection>
<developerConnection>scm:git:git@github.com: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 Down Expand Up @@ -98,15 +98,17 @@
<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>
Expand Down
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:trygvis@inamo.no">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);
}
}

}
13 changes: 6 additions & 7 deletions src/main/java/org/codehaus/plexus/resource/PlexusResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
/**
* 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
Expand All @@ -49,7 +48,7 @@ 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;
Expand All @@ -59,7 +58,7 @@ public interface PlexusResource
* 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;
Expand All @@ -68,7 +67,7 @@ public interface PlexusResource
* <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;
Expand All @@ -77,7 +76,7 @@ public interface PlexusResource
* <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;
Expand Down
Loading

0 comments on commit 512f188

Please sign in to comment.