Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Fixong code format
Browse files Browse the repository at this point in the history
  • Loading branch information
velo committed Jan 23, 2011
1 parent aa54f88 commit 415c719
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 84 deletions.
27 changes: 27 additions & 0 deletions .gitignore
@@ -0,0 +1,27 @@
# Ignores for Sonatype Nexus Core
# Language is Java
# Build tool is Apache Maven2/3
# IDE used is Eclipse MSE
# so, we have to ignore all the specifics of these above

# Eclipse related (and M2e)
.classpath
.project
.settings/
test-output/

# Maven related (and some plugins)
target/
*.ser
*.ec

# Intellij
*.ipr
*.iml
*.iws

# Other
.svn/
bin/

.scala_dependencies
Expand Up @@ -33,7 +33,6 @@
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
Expand All @@ -51,29 +50,25 @@
import org.sonatype.flexmojos.optimizer.OptimizerMojo;

/**
* Goal that allows for manual generation of RSLs. This goal is intended to be
* run out of the build lifecycle to install or deploy SWF files for SWC
* artifacts missing their RSL counterpart.
*
* Tipical usage examples are:
*
* Goal that allows for manual generation of RSLs. This goal is intended to be run out of the build lifecycle to install
* or deploy SWF files for SWC artifacts missing their RSL counterpart. Tipical usage examples are:
* <ul>
* <li>to generate and install (or deploy) a specific artifact RSL</br>
* <code>mvn flexmojos:install-rsl -DartifactId= -DgroupId= -Dversion= -Dclassifier=</code>
* </li>
*
* <code>mvn flexmojos:install-rsl -DartifactId= -DgroupId= -Dversion= -Dclassifier=</code></li>
* <li>to generate and install (or deploy) all direct dependencies RSLs</br>
* <code>mvn flexmojos:install-rsl -Ddependencies=direct</code></li>
*
* <li>to generate and install (or deploy) all transitive dependencies RSLs</br>
* <code>mvn flexmojos:install-rsl -Ddependencies=transitive</code></li>
*
* @author Roberto Lo Giacco (rlogiacco@gmail.com)
*
* @goal install-rsl
* @requiresDependencyResolution
* @requiresDirectInvocation true
* @requiresProject false
*/
public class InstallerMojo extends OptimizerMojo implements MavenMojo
public class InstallerMojo
extends OptimizerMojo
implements MavenMojo
{

/**
Expand Down Expand Up @@ -131,6 +126,7 @@ public class InstallerMojo extends OptimizerMojo implements MavenMojo
* @required
*/
private ArtifactDeployer deployer;

/**
* @optional
* @parameter expression="${excludeTransitive}" default-value="false"
Expand Down Expand Up @@ -217,7 +213,7 @@ public class InstallerMojo extends OptimizerMojo implements MavenMojo
* @component
* @readonly
* @required
* */
*/
protected ArtifactResolver resolver;

/**
Expand All @@ -236,7 +232,7 @@ public class InstallerMojo extends OptimizerMojo implements MavenMojo
* @readonly
* @required
*/
protected List remoteRepositories;
protected List<ArtifactRepository> remoteRepositories;

/**
* @component
Expand All @@ -245,33 +241,24 @@ public class InstallerMojo extends OptimizerMojo implements MavenMojo
*/
protected ArtifactInstaller installer;

/**
* @component
*
* @readonly
* @required
*/
private ArtifactMetadataSource artifactMetadataSource;

@Override
public void execute() throws MojoExecutionException, MojoFailureException
public void execute()
throws MojoExecutionException, MojoFailureException
{
if ( dependencies == null )
{
Artifact artifact = artifactFactory.createArtifactWithClassifier(
groupId, artifactId, version, originalType, classifier );
Artifact artifact =
artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, originalType, classifier );

Artifact rslArtifact = artifactFactory
.createArtifactWithClassifier( groupId, artifactId,
version, rslExtension, classifier );
Artifact rslArtifact =
artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, rslExtension, classifier );

try
{
resolver.resolve( artifact, remoteRepositories, localRepository );
try
{
resolver.resolve( rslArtifact, remoteRepositories,
localRepository );
resolver.resolve( rslArtifact, remoteRepositories, localRepository );
getLog().info( "Overwriting RSL Artifact" );
}
catch ( Exception e )
Expand All @@ -282,8 +269,7 @@ public void execute() throws MojoExecutionException, MojoFailureException
}
catch ( Exception e )
{
throw new MojoExecutionException( "Artifact resolution failed",
e );
throw new MojoExecutionException( "Artifact resolution failed", e );
}
}
else if ( "direct".equalsIgnoreCase( dependencies ) )
Expand All @@ -297,38 +283,35 @@ else if ( "transitive".equalsIgnoreCase( dependencies ) )
}
else
{
throw new MojoExecutionException(
"No valid execution parameters found" );
throw new MojoExecutionException( "No valid execution parameters found" );
}
}

/**
* @throws MojoExecutionException
* @throws MojoFailureException
*/
protected void processDependencies() throws MojoExecutionException, MojoFailureException
@SuppressWarnings( "unchecked" )
protected void processDependencies()
throws MojoExecutionException, MojoFailureException
{
// add filters in well known order, least specific to most specific
FilterArtifacts filter = new FilterArtifacts();
filter.addFilter( new ProjectTransitivityFilter( project
.getDependencyArtifacts(), this.excludeTransitive ) );
filter.addFilter( new ProjectTransitivityFilter( project.getDependencyArtifacts(), this.excludeTransitive ) );
filter.addFilter( new TypeFilter( this.includeTypes, this.excludeTypes ) );
filter.addFilter( new ClassifierFilter( this.includeClassifiers,
this.excludeClassifiers ) );
filter.addFilter( new GroupIdFilter( this.includeGroupIds,
this.excludeGroupIds ) );
filter.addFilter( new ArtifactIdFilter( this.includeArtifactIds,
this.excludeArtifactIds ) );
filter.addFilter( new ClassifierFilter( this.includeClassifiers, this.excludeClassifiers ) );
filter.addFilter( new GroupIdFilter( this.includeGroupIds, this.excludeGroupIds ) );
filter.addFilter( new ArtifactIdFilter( this.includeArtifactIds, this.excludeArtifactIds ) );

// start with all artifacts.
Set< Artifact > artifacts = project.getArtifacts();
Set<Artifact> artifacts = project.getArtifacts();

// perform filtering
try
{
artifacts = filter.filter( artifacts );

Iterator< Artifact > iterator = artifacts.iterator();
Iterator<Artifact> iterator = artifacts.iterator();
while ( iterator.hasNext() )
{
Artifact artifact = iterator.next();
Expand All @@ -352,32 +335,30 @@ protected void processDependencies() throws MojoExecutionException, MojoFailureE
outputDirectory.mkdirs();
for ( Artifact artifact : artifacts )
{
Artifact rslArtifact = artifactFactory
.createArtifactWithClassifier( artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(), rslExtension, null );
Artifact rslArtifact =
artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), rslExtension, null );

processDependency( artifact, rslArtifact );
}
}
}

/**
* @param artifact
* @param rslArtifact
* @throws MojoExecutionException
*/
protected void processDependency(Artifact artifact, Artifact rslArtifact)
throws MojoExecutionException
protected void processDependency( Artifact artifact, Artifact rslArtifact )
throws MojoExecutionException
{

try
{
// lookup RSL artifact
resolver.resolve( rslArtifact, remoteRepositories, localRepository );
getLog().debug( "Artifact RSL found: " + rslArtifact );
File outputFile = new File( outputDirectory,
getFormattedFileName( rslArtifact ) );
File outputFile = new File( outputDirectory, getFormattedFileName( rslArtifact ) );
try
{
FileUtils.copyFile( rslArtifact.getFile(), outputFile );
Expand All @@ -399,52 +380,43 @@ protected void processDependency(Artifact artifact, Artifact rslArtifact)
resolver.resolve( artifact, remoteRepositories, localRepository );
archive = newZipFile( artifact.getFile() );
input = readLibrarySwf( artifact.getFile(), archive );
File outputFile = new File( outputDirectory,
getFormattedFileName( rslArtifact ) );
File outputFile = new File( outputDirectory, getFormattedFileName( rslArtifact ) );
output = new FileOutputStream( outputFile );
Artifact originalArtifact = artifactFactory
.createArtifactWithClassifier( artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(), artifact.getType(),
originalClassifier );
Artifact originalArtifact =
artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), artifact.getType(),
originalClassifier );

if ( optimizeRsls )
{
originalFile = new File( project.getBuild()
.getOutputDirectory(), artifact.getFile().getName()
originalFile =
new File( project.getBuild().getOutputDirectory(), artifact.getFile().getName()
+ originalClassifier );
FileUtils.copyFile( artifact.getFile(), originalFile );
getLog().info( "Attempting to optimize: " + artifact );
long initialSize = artifact.getFile().length() / 1024;
optimize( input, output );
long optimizedSize = outputFile.length() / 1024;
getLog().info(
"\t\tsize reduced from " + initialSize + "kB to "
+ optimizedSize + "kB" );
getLog().info( "\t\tsize reduced from " + initialSize + "kB to " + optimizedSize + "kB" );

updateDigest( outputFile, originalFile );
}
if ( deploy )
{
ArtifactRepository deploymentRepository = project
.getDistributionManagementArtifactRepository();
ArtifactRepository deploymentRepository = project.getDistributionManagementArtifactRepository();
if ( backup && optimizeRsls )
{
deployer.deploy( originalFile, originalArtifact,
deploymentRepository, localRepository );
deployer.deploy( originalFile, originalArtifact, deploymentRepository, localRepository );
}
deployer.deploy( outputFile, rslArtifact,
deploymentRepository, localRepository );
deployer.deploy( outputFile, rslArtifact, deploymentRepository, localRepository );
}
else
{
if ( backup && optimizeRsls )
{
installer.install( originalFile, originalArtifact,
localRepository );
installer.install( originalFile, originalArtifact, localRepository );
}
installer
.install( outputFile, rslArtifact, localRepository );
installer.install( outputFile, rslArtifact, localRepository );
}
}
catch ( Exception e )
Expand Down Expand Up @@ -478,7 +450,7 @@ protected void processDependency(Artifact artifact, Artifact rslArtifact)
* @param artifact
* @return
*/
protected String getFormattedFileName(Artifact artifact)
protected String getFormattedFileName( Artifact artifact )
{
String destFileName = null;
if ( artifact.getFile() != null && !stripVersion )
Expand All @@ -499,14 +471,13 @@ protected String getFormattedFileName(Artifact artifact)

String classifierString = "";

if ( artifact.getClassifier() != null
&& !artifact.getClassifier().trim().isEmpty() )
if ( artifact.getClassifier() != null && !artifact.getClassifier().trim().isEmpty() )
{
classifierString = "-" + artifact.getClassifier();
}

destFileName = artifact.getArtifactId() + versionString
+ classifierString + "."
destFileName =
artifact.getArtifactId() + versionString + classifierString + "."
+ artifact.getArtifactHandler().getExtension();
}
return destFileName;
Expand Down
Expand Up @@ -179,7 +179,7 @@ public void execute()
}

String packaging = project.getPackaging();
if ( ! ("war".equals( packaging ) || "swf".equals( packaging ) ) )
if ( !( "war".equals( packaging ) || "swf".equals( packaging ) ) )
{
getLog().warn( "'copy-flex-resources' was intended to run on war or swf project" );
}
Expand Down

0 comments on commit 415c719

Please sign in to comment.