Skip to content

Commit

Permalink
Fixed config of freeze4 example. Got rid of dual repo experiment.
Browse files Browse the repository at this point in the history
  • Loading branch information
nawroth committed May 7, 2012
1 parent 90a94ed commit 9888d1b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 106 deletions.
1 change: 1 addition & 0 deletions example-thaw/pom.xml
Expand Up @@ -24,6 +24,7 @@
<groupId>org.neo4j.build.plugins</groupId>
<artifactId>ease-example-freeze4</artifactId>
<version>1-SNAPSHOT</version>
<type>pom</type>
</dependency>
</dependencies>

Expand Down
85 changes: 28 additions & 57 deletions plugin/src/main/java/org/neo4j/build/plugins/ease/ThawMojo.java
Expand Up @@ -133,42 +133,30 @@ public class ThawMojo extends AbstractMojo
*/
private ArtifactCollector artifactCollector;

/**
* Lock down deoendency traversal to this repo.
*/
private ArtifactRepository thawRepository = null;

@Override
public void execute() throws MojoExecutionException
{
project.getAttachedArtifacts()
.clear();

thawRepository = new ThawRepository( "file:///home/anders/repo" );
project.getAttachedArtifacts().clear();

for ( Artifact dependency : getDependencies() )
{
Artifact findArtifactsArtifact = artifactFactory.createArtifactWithClassifier(
dependency.getGroupId(), dependency.getArtifactId(),
dependency.getVersion(), "txt", "artifacts" );
Artifact findArtifactsArtifact = artifactFactory.createArtifactWithClassifier( dependency.getGroupId(),
dependency.getArtifactId(), dependency.getVersion(), "txt", "artifacts" );
Artifact artifactsArtifact = localRepository.find( findArtifactsArtifact );
File artifactsFile = artifactsArtifact.getFile();
if ( !artifactsFile.exists() )
{
throw new MojoExecutionException(
"Could not find an artifact list for: " + dependency );
throw new MojoExecutionException( "Could not find an artifact list for: " + dependency );
}

String[] lines = null;
try
{
lines = FileUtils.fileRead( artifactsFile, "UTF-8" )
.split( "\n" );
lines = FileUtils.fileRead( artifactsFile, "UTF-8" ).split( "\n" );
}
catch ( IOException ioe )
{
throw new MojoExecutionException(
"Could not read artifact list for: " + dependency, ioe );
throw new MojoExecutionException( "Could not read artifact list for: " + dependency, ioe );
}
boolean pomWasAttached = false;
for ( String artifactString : lines )
Expand All @@ -182,67 +170,54 @@ public void execute() throws MojoExecutionException
}
if ( !pomWasAttached )
{
findAndAttachExternalArtifact( dependency.getGroupId(),
dependency.getArtifactId(), dependency.getVersion(),
"pom", null );
findAndAttachExternalArtifact( dependency.getGroupId(), dependency.getArtifactId(),
dependency.getVersion(), "pom", null );
}
}
}

private void findAndAttachExternalArtifact( String groupId,
String artifactId, String version, String type, String classifier )
throws MojoExecutionException
private void findAndAttachExternalArtifact( String groupId, String artifactId, String version, String type,
String classifier ) throws MojoExecutionException
{
Artifact findArtifact = createArtifact( groupId, artifactId, version,
type, classifier );
Artifact findArtifact = createArtifact( groupId, artifactId, version, type, classifier );
findAndAttachExternalArtifact( findArtifact );
}

private void findAndAttachExternalArtifact( Artifact findArtifact )
throws MojoExecutionException
private void findAndAttachExternalArtifact( Artifact findArtifact ) throws MojoExecutionException
{
if ( findArtifact == null )
{
throw new MojoExecutionException( "Could not find artifact: "
+ findArtifact );
throw new MojoExecutionException( "Could not find artifact: " + findArtifact );
}
Artifact artifactToAttach = localRepository.find( findArtifact );

String fileName = artifactToAttach.getFile()
.getName();
File destination = new File( new File( project.getBuild()
.getDirectory() ), fileName );
String fileName = artifactToAttach.getFile().getName();
File destination = new File( new File( project.getBuild().getDirectory() ), fileName );
try
{
FileUtils.copyFileIfModified( artifactToAttach.getFile(),
destination );
FileUtils.copyFileIfModified( artifactToAttach.getFile(), destination );
}
catch ( IOException ioe )
{
throw new MojoExecutionException( "Could not copy file: "
+ fileName, ioe );
throw new MojoExecutionException( "Could not copy file: " + fileName, ioe );
}
artifactToAttach.setFile( destination );

project.addAttachedArtifact( artifactToAttach );
getLog().info( "Attached: " + artifactToAttach );
}

private Artifact createArtifact( String groupId, String artifactId,
String version, String type, String classifier )
private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
{
return artifactFactory.createArtifactWithClassifier( groupId,
artifactId, version, type, classifier );
return artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
}

private Artifact createArtifact( String coords )
throws MojoExecutionException
private Artifact createArtifact( String coords ) throws MojoExecutionException
{
String[] strings = coords.split( ":" );
if ( strings.length < 4 || strings.length > 5 )
{
throw new MojoExecutionException( "Can not parse coordinates: "
+ coords );
throw new MojoExecutionException( "Can not parse coordinates: " + coords );
}
String groupId = strings[0];
String artifactId = strings[1];
Expand Down Expand Up @@ -288,29 +263,26 @@ private Set<Artifact> getDependencies() throws MojoExecutionException
return artifacts;
}

private Set<Artifact> getFilteredTransitiveDependencies(
ArtifactFilter filter ) throws MojoExecutionException
private Set<Artifact> getFilteredTransitiveDependencies( ArtifactFilter filter ) throws MojoExecutionException
{
HashSet<Artifact> artifacts = new HashSet<Artifact>();
DependencyNode rootNode = null;
try
{
rootNode = treeBuilder.buildDependencyTree( project,
localRepository, artifactFactory, artifactMetadataSource,
null, artifactCollector );
rootNode = treeBuilder.buildDependencyTree( project, localRepository, artifactFactory,
artifactMetadataSource, null, artifactCollector );
}
catch ( DependencyTreeBuilderException dtbe )
{
throw new MojoExecutionException(
"Failed to traverse dependencies.", dtbe );
throw new MojoExecutionException( "Failed to traverse dependencies.", dtbe );
}

CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor();

if ( filterEarly )
{
FilteringDependencyNodeVisitor filteringVisitor = new FilteringDependencyNodeVisitor(
visitor, new ArtifactDependencyNodeFilter( filter ) );
FilteringDependencyNodeVisitor filteringVisitor = new FilteringDependencyNodeVisitor( visitor,
new ArtifactDependencyNodeFilter( filter ) );

rootNode.accept( filteringVisitor );
}
Expand All @@ -323,8 +295,7 @@ private Set<Artifact> getFilteredTransitiveDependencies(
for ( DependencyNode dependencyNode : nodes )
{
int state = dependencyNode.getState();
if ( state == DependencyNode.INCLUDED
&& filter.include( dependencyNode.getArtifact() ) )
if ( state == DependencyNode.INCLUDED && filter.include( dependencyNode.getArtifact() ) )
{
artifacts.add( dependencyNode.getArtifact() );
}
Expand Down

This file was deleted.

0 comments on commit 9888d1b

Please sign in to comment.