Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added configuration for excluding artifacts and setting dependency re…

…po location. Some refactoring.
  • Loading branch information...
commit ef73b8759b7ce403b6d536c12b8462e106c95a18 1 parent 338c7f4
Anders Nawroth authored
6 example-thaw/pom.xml
@@ -30,9 +30,9 @@
30 30 <goal>thaw</goal>
31 31 </goals>
32 32 <configuration>
33   - <groupIds>
34   - <groupId>org.neo4j.build.plugins</groupId>
35   - </groupIds>
  33 + <includeGroupIds>
  34 + <includeGroupId>org.neo4j.build.plugins</includeGroupId>
  35 + </includeGroupIds>
36 36 </configuration>
37 37 </execution>
38 38 </executions>
6 plugin/pom.xml
@@ -285,9 +285,9 @@
285 285 <goal>thaw</goal>
286 286 </goals>
287 287 <configuration>
288   - <groupIds>
289   - <groupId>org.neo4j</groupId>
290   - </groupIds>
  288 + <includeGroupIds>
  289 + <includeGroupId>org.neo4j</includeGroupId>
  290 + </includeGroupIds>
291 291 </configuration>
292 292 </execution>
293 293 </executions>
188 plugin/src/main/java/org/neo4j/build/plugins/ease/ThawMojo.java
@@ -21,11 +21,14 @@
21 21
22 22 import java.io.File;
23 23 import java.io.IOException;
  24 +import java.net.MalformedURLException;
  25 +import java.util.Collections;
24 26 import java.util.List;
25 27
26 28 import org.apache.maven.artifact.Artifact;
27 29 import org.apache.maven.artifact.factory.ArtifactFactory;
28 30 import org.apache.maven.artifact.repository.ArtifactRepository;
  31 +import org.apache.maven.artifact.repository.MavenArtifactRepository;
29 32 import org.apache.maven.model.Dependency;
30 33 import org.apache.maven.plugin.AbstractMojo;
31 34 import org.apache.maven.plugin.MojoExecutionException;
@@ -48,7 +51,23 @@
48 51 * @parameter
49 52 * @required
50 53 */
51   - protected List<String> groupIds;
  54 + protected List<String> includeGroupIds;
  55 +
  56 + /**
  57 + * ArtifactIds to exclude from the project.
  58 + *
  59 + * @parameter
  60 + */
  61 + protected List<String> excludeArtifactIds;
  62 +
  63 + /**
  64 + * Local repo location for fetching dependencies to thaw. When this is
  65 + * defined, the dependencies to thaw will be fetched from there and not from
  66 + * the usual local repo. Using this setting is recommended.
  67 + *
  68 + * @parameter
  69 + */
  70 + protected String thawDependencyRepositoryLocation;
52 71
53 72 /**
54 73 * @parameter default-value="${project}"
@@ -64,7 +83,7 @@
64 83 * @required
65 84 * @readonly
66 85 */
67   - protected ArtifactFactory artFactory;
  86 + protected ArtifactFactory artifactFactory;
68 87
69 88 /**
70 89 * Location of the local repository.
@@ -85,18 +104,49 @@ public void execute() throws MojoExecutionException
85 104 {
86 105 project.getAttachedArtifacts()
87 106 .clear();
  107 +
  108 + if ( excludeArtifactIds == null )
  109 + {
  110 + excludeArtifactIds = Collections.emptyList();
  111 + }
  112 +
  113 + ArtifactRepository dependencyRepo = null;
  114 + if ( thawDependencyRepositoryLocation == null )
  115 + {
  116 + dependencyRepo = localRepository;
  117 + }
  118 + else
  119 + {
  120 + dependencyRepo = new MavenArtifactRepository();
  121 + try
  122 + {
  123 + dependencyRepo.setUrl( new File(
  124 + thawDependencyRepositoryLocation ).toURI()
  125 + .toURL()
  126 + .toExternalForm() );
  127 + }
  128 + catch ( MalformedURLException mue )
  129 + {
  130 + throw new MojoExecutionException(
  131 + "Could not parse thaw dependency repository location: "
  132 + + thawDependencyRepositoryLocation, mue );
  133 + }
  134 + }
88 135 for ( Dependency dependency : project.getDependencies() )
89 136 {
90   - if ( groupIds.contains( dependency.getGroupId() ) )
  137 + if ( includeGroupIds.contains( dependency.getGroupId() )
  138 + && !excludeArtifactIds.contains( dependency.getArtifactId() ) )
91 139 {
92   - Artifact findArtifactsArtifact = artFactory.createArtifactWithClassifier(
  140 + Artifact findArtifactsArtifact = artifactFactory.createArtifactWithClassifier(
93 141 dependency.getGroupId(), dependency.getArtifactId(),
94 142 dependency.getVersion(), "txt", "artifacts" );
95 143 Artifact artifactsArtifact = localRepository.find( findArtifactsArtifact );
96 144 File artifactsFile = artifactsArtifact.getFile();
97 145 if ( !artifactsFile.exists() )
98 146 {
99   - continue;
  147 + throw new MojoExecutionException(
  148 + "Could not find an artifact list for: "
  149 + + dependency );
100 150 }
101 151
102 152 String[] lines = null;
@@ -113,36 +163,17 @@ public void execute() throws MojoExecutionException
113 163 }
114 164 for ( String artifactString : lines )
115 165 {
116   - String[] strings = artifactString.split( ":" );
117   - if ( strings.length < 4 || strings.length > 5 )
118   - {
119   - getLog().error(
120   - "Can't parse artifact coordinates: "
121   - + artifactString );
122   - continue;
123   - }
124   - String groupId = strings[0];
125   - String artifactId = strings[1];
126   - String type = strings[2];
127   - String version = null;
128   - String classifier = null;
129   - if ( strings.length == 5 )
  166 + Artifact findArtifact = createArtifact( artifactString );
  167 + if ( !"pom".equals( findArtifact.getType() ) )
130 168 {
131   - version = strings[4];
132   - classifier = strings[3];
  169 + // add the pom as well
  170 + findAndAttachExternalArtifact(
  171 + findArtifact.getGroupId(),
  172 + findArtifact.getArtifactId(),
  173 + findArtifact.getVersion(), "pom", null );
133 174 }
134   - else if ( strings.length == 4 )
135   - {
136   - version = strings[3];
137   - if ( !"pom".equals( type ) )
138   - {
139   - // add the pom as well
140   - findAndAttachExternalArtifact( groupId, artifactId,
141   - version, "pom", null );
142   - }
143   - }
144   - findAndAttachExternalArtifact( groupId, artifactId,
145   - version, type, classifier );
  175 +
  176 + findAndAttachExternalArtifact( findArtifact );
146 177 }
147 178 }
148 179 }
@@ -150,38 +181,77 @@ else if ( strings.length == 4 )
150 181
151 182 private void findAndAttachExternalArtifact( String groupId,
152 183 String artifactId, String version, String type, String classifier )
  184 + throws MojoExecutionException
153 185 {
154   - Artifact findArtifact = artFactory.createArtifactWithClassifier(
155   - groupId, artifactId, version, type, classifier );
156   - if ( findArtifact != null )
  186 + Artifact findArtifact = createArtifact( groupId, artifactId, version,
  187 + type, classifier );
  188 + findAndAttachExternalArtifact( findArtifact );
  189 + }
  190 +
  191 + private void findAndAttachExternalArtifact( Artifact findArtifact )
  192 + throws MojoExecutionException
  193 + {
  194 + if ( findArtifact == null )
157 195 {
158   - Artifact artifactToAttach = localRepository.find( findArtifact );
159   - if ( "pom".equals( type ) )
  196 + throw new MojoExecutionException( "Could not find artifact: "
  197 + + findArtifact );
  198 + }
  199 + Artifact artifactToAttach = localRepository.find( findArtifact );
  200 + if ( "pom".equals( artifactToAttach.getType() ) )
  201 + {
  202 + // point to a copy of the pom, otherwise it gets
  203 + // corrupted as target and source are the same.
  204 + // doesn't seem to happen to other artifacts.
  205 + String fileName = artifactToAttach.getFile()
  206 + .getName();
  207 + System.out.println( "file: " + fileName );
  208 + File destination = new File( new File( project.getBuild()
  209 + .getDirectory() ), fileName );
  210 + try
160 211 {
161   - // point to a copy of the pom, otherwise it gets
162   - // corrupted as target and source are the same.
163   - // doesn't seem to happen to other artifacts.
164   - String fileName = artifactToAttach.getFile()
165   - .getName();
166   - File destination = new File( new File( project.getBuild()
167   - .getDirectory() ), fileName );
168   - try
169   - {
170   - FileUtils.copyFileIfModified( artifactToAttach.getFile(),
171   - destination );
172   - }
173   - catch ( IOException e )
174   - {
175   - e.printStackTrace();
176   - }
177   - artifactToAttach.setFile( destination );
  212 + FileUtils.copyFileIfModified( artifactToAttach.getFile(),
  213 + destination );
178 214 }
179   - project.addAttachedArtifact( artifactToAttach );
180   - System.out.println( "added: " + artifactToAttach );
  215 + catch ( IOException e )
  216 + {
  217 + e.printStackTrace();
  218 + }
  219 + artifactToAttach.setFile( destination );
181 220 }
182   - else
  221 + project.addAttachedArtifact( artifactToAttach );
  222 + System.out.println( "added: " + artifactToAttach );
  223 + }
  224 +
  225 + private Artifact createArtifact( String groupId, String artifactId,
  226 + String version, String type, String classifier )
  227 + {
  228 + return artifactFactory.createArtifactWithClassifier( groupId,
  229 + artifactId, version, type, classifier );
  230 + }
  231 +
  232 + private Artifact createArtifact( String coords )
  233 + throws MojoExecutionException
  234 + {
  235 + String[] strings = coords.split( ":" );
  236 + if ( strings.length < 4 || strings.length > 5 )
  237 + {
  238 + throw new MojoExecutionException( "Can not parse coordinates: "
  239 + + coords );
  240 + }
  241 + String groupId = strings[0];
  242 + String artifactId = strings[1];
  243 + String type = strings[2];
  244 + String version = null;
  245 + String classifier = null;
  246 + if ( strings.length == 5 )
  247 + {
  248 + version = strings[4];
  249 + classifier = strings[3];
  250 + }
  251 + else if ( strings.length == 4 )
183 252 {
184   - getLog().error( "Could not find artifact: " + findArtifact );
  253 + version = strings[3];
185 254 }
  255 + return createArtifact( groupId, artifactId, version, type, classifier );
186 256 }
187 257 }

0 comments on commit ef73b87

Please sign in to comment.
Something went wrong with that request. Please try again.