Skip to content
This repository
Browse code

Fixed up maven import

  • Loading branch information...
commit 989ded15c730ab1fc4b54c7f028384a2c2364b33 2 parents dab8b24 + d36c7dc
Joel Ossher authored May 01, 2012
1  infrastructure/tools/java/repository-manager/.classpath
@@ -6,5 +6,6 @@
6 6
 	<classpathentry combineaccessrules="false" kind="src" path="/utilities"/>
7 7
 	<classpathentry combineaccessrules="false" kind="src" path="/core-repository-manager"/>
8 8
 	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
  9
+	<classpathentry kind="lib" path="/lib/guava-11.0.1.jar"/>
9 10
 	<classpathentry kind="output" path="bin"/>
10 11
 </classpath>
61  ...ure/tools/java/repository-manager/src/edu/uci/ics/sourcerer/tools/java/repo/importers/MavenImporter.java
@@ -206,31 +206,54 @@ public void characters(char[] ch, int start, int length) {
206 206
             } catch (SAXException | IOException e) {
207 207
               logger.log(Level.SEVERE, "Error reading maven metadata.", e);
208 208
             }
  209
+            // Verify the artifact info matches properly
  210
+            if (!handler.versions.isEmpty()) {
  211
+              String testGroup = next.getParent().substring(root.getPath().length()).replace(File.separatorChar, '.');
  212
+              if (!testGroup.isEmpty()) {
  213
+                testGroup = testGroup.substring(1);
  214
+              }
  215
+              if (!testGroup.equals(handler.groupID)) {
  216
+                logger.info("Group mismatch for: " + next.getPath() + " " + testGroup);
  217
+                handler.groupID = testGroup;
  218
+              }
  219
+              if (!next.getName().equals(handler.artifactID)) {
  220
+                logger.info("Artifact mismatch for: " + next.getPath());
  221
+                handler.artifactID = next.getName();
  222
+              }
  223
+            }
209 224
             // Look up the all the version
210 225
             for (String v : handler.versions) {
211 226
               File version = new File(next, v);
212 227
               if (version.isDirectory()) {
213  
-                String jarSuffix = version.getName() + ".jar";
214  
-                String sourceSuffix = version.getName() + "-sources.jar";
215  
-                File jar = null;
216  
-                File source = null;
217  
-                for (File file : version.listFiles()) {
218  
-                  if (file.getName().endsWith(jarSuffix)) {
219  
-                    if (jar == null) {
220  
-                      jar = file;
221  
-                    } else {
222  
-                      logger.info("Multiple jar files for " + version.getAbsolutePath());
223  
-                    }
224  
-                  } else if (file.getName().endsWith(sourceSuffix)) {
225  
-                    if (source == null) {
226  
-                      source = file;
227  
-                    } else {
228  
-                      logger.info("Multiple source files for " + version.getAbsolutePath());
  228
+                File jar = new File(version, handler.artifactID + "-" + version.getName() + ".jar");
  229
+                File source = new File(version, handler.artifactID + "-" + version.getName() + "-sources.jar");
  230
+                if (!jar.exists()) {
  231
+                  jar = null;
  232
+                }
  233
+                if (!source.exists()) {
  234
+                  source = null;
  235
+                }
  236
+                if (jar == null || source == null) {
  237
+                  String jarSuffix = version.getName() + ".jar";
  238
+                  String sourceSuffix = version.getName() + "-sources.jar";
  239
+                  for (File file : version.listFiles()) {
  240
+                    if (file.getName().endsWith(jarSuffix)) {
  241
+                      if (jar == null) {
  242
+                        jar = file;
  243
+                      } else if (!jar.equals(file)) {
  244
+                        logger.info("Multiple jar files for " + version.getAbsolutePath());
  245
+                      }
  246
+                    } else if (file.getName().endsWith(sourceSuffix)) {
  247
+                      if (source == null) {
  248
+                        source = file;
  249
+                      } else if (!source.equals(file)) {
  250
+                        logger.info("Multiple source files for " + version.getAbsolutePath());
  251
+                      }
229 252
                     }
230 253
                   }
231 254
                 }
232 255
                 if (jar == null) {
233  
-                  logger.info("Unable to find jar for " + version.getAbsolutePath());
  256
+//                  logger.info("Unable to find jar for " + version.getAbsolutePath());
234 257
                 } else {
235 258
                   repo.addMavenJarFile(jar, source, handler.groupID, handler.artifactID, version.getName());
236 259
                 }
@@ -241,7 +264,9 @@ public void characters(char[] ch, int start, int length) {
241 264
           }
242 265
         }
243 266
         for (File child : next.listFiles()) {
244  
-          stack.add(child);
  267
+          if (!child.getName().startsWith(".")) {
  268
+            stack.add(child);
  269
+          }
245 270
         }
246 271
       }
247 272
     }
15  .../tools/java/repository-manager/src/edu/uci/ics/sourcerer/tools/java/repo/model/internal/JarFileImpl.java
@@ -115,10 +115,21 @@ public RepoFileImpl getSourceFile() {
115 115
   
116 116
   @Override
117 117
   public String toString() {
118  
-    if (properties.VERSION.getValue() == null) {
  118
+    String group = properties.GROUP.getValue();
  119
+    String name = properties.NAME.getValue();
  120
+    String version = properties.VERSION.getValue();
  121
+    if (version == null) {
119 122
       return properties.NAME.getValue();
120 123
     } else {
121  
-      return properties.NAME.getValue() + " (" + properties.VERSION.getValue() + ")";
  124
+      StringBuilder builder = new StringBuilder();
  125
+      if (group != null) {
  126
+        builder.append(group);
  127
+      }
  128
+      builder.append(name);
  129
+      if (version != null) {
  130
+        builder.append(" (").append(version).append(")");
  131
+      }
  132
+      return builder.toString();
122 133
     }
123 134
   }
124 135
 
44  ...java/repository-manager/src/edu/uci/ics/sourcerer/tools/java/repo/model/internal/JavaRepositoryImpl.java
@@ -24,6 +24,7 @@
24 24
 import java.util.HashMap;
25 25
 import java.util.LinkedList;
26 26
 import java.util.Map;
  27
+import java.util.logging.Level;
27 28
 
28 29
 import edu.uci.ics.sourcerer.tools.core.repo.model.ContentFile;
29 30
 import edu.uci.ics.sourcerer.tools.core.repo.model.ModifiableSourceRepository;
@@ -245,13 +246,26 @@ public void addMavenJarFile(File jar, File source, String group, String artifact
245 246
       loadMavenJarIndex();
246 247
     }
247 248
     String hash = FileUtils.computeHash(jar);
248  
-    if (mavenJarIndex.containsKey(hash)) {
249  
-      logger.info("Repository already contains a copy of " + group + "." + artifact);
  249
+    while (mavenJarIndex.containsKey(hash)) {
  250
+      logger.info("Difficulty matching: " + group + "." + artifact + " (" + version + ")");
  251
+      JarFileImpl mavenJar = mavenJarIndex.get(hash);
  252
+      logger.info("  Found duplicate at: " + mavenJar);
  253
+      JarProperties properties = mavenJar.getProperties();
  254
+      // If it's not exactly equal, just add the duplicate, giving the original priority
  255
+      if (group.equals(properties.GROUP.getValue()) && artifact.equals(properties.NAME.getValue()) && version.equals(properties.VERSION.getValue())) {
  256
+        return;
  257
+      }
  258
+      // Add a 0 to the end of the hash
  259
+      hash += "0";
  260
+    } 
  261
+    String subDir = group.replace('.', '/') + "/" + artifact + "/" + version;
  262
+
  263
+    RepoFileImpl dir = repoRoot.getChild(JARS_DIRECTORY).getChild(MAVEN_JARS_DIRECTORY).getChild(subDir);
  264
+
  265
+    // Verify there's no overlap
  266
+    if (dir.exists()) {
  267
+      logger.log(Level.SEVERE, "Directory already exists for: " + group + "." + artifact + " (" + version + ")");
250 268
     } else {
251  
-      String subDir = group.replace('.', '/') + "/" + artifact + "/" + version;
252  
-  
253  
-      RepoFileImpl dir = repoRoot.getChild(JARS_DIRECTORY).getChild(MAVEN_JARS_DIRECTORY).getChild(subDir);
254  
-      
255 269
       // Make the directory
256 270
       dir.makeDirs();
257 271
       
@@ -263,16 +277,14 @@ public void addMavenJarFile(File jar, File source, String group, String artifact
263 277
       
264 278
       // Populate the properties
265 279
       JarFileImpl newJar = JarFileImpl.create(dir);
266  
-      
267  
-      if (newJar != null) {
268  
-        JarProperties properties = newJar.getProperties();
269  
-        properties.NAME.setValue(artifact);
270  
-        properties.GROUP.setValue(group);
271  
-        properties.SOURCE.setValue(JarSource.MAVEN);
272  
-        properties.HASH.setValue(hash);
273  
-        properties.VERSION.setValue(version);
274  
-        properties.save();
275  
-      }
  280
+
  281
+      JarProperties properties = newJar.getProperties();
  282
+      properties.NAME.setValue(artifact);
  283
+      properties.GROUP.setValue(group);
  284
+      properties.SOURCE.setValue(JarSource.MAVEN);
  285
+      properties.HASH.setValue(hash);
  286
+      properties.VERSION.setValue(version);
  287
+      properties.save();
276 288
     }
277 289
   }
278 290
   

0 notes on commit 989ded1

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