Last active
July 6, 2016 10:30
-
-
Save xylifyx2/c232dfe9823df2bfdb673421d67316be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright © 2016, QIAGEN Aarhus A/S. All rights reserved. | |
*/ | |
package com.qiagen.sky.buildutil; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
/** | |
* run as java Importer [dirtosearch] | |
**/ | |
public class Importer { | |
private static final String REPO_ID = "nexus-releases"; | |
private static final String REPO_URL = "http://nexus01/nexus/repository/maven-releases/"; | |
private static final String MVN_CLI = "mvn"; | |
private String directory; | |
private PrintWriter out; | |
/** | |
* @param directory | |
* local repository directory | |
*/ | |
public Importer(String directory) { | |
super(); | |
this.directory = directory; | |
this.out = new PrintWriter(System.out); | |
} | |
// SUPPRESS CHECKSTYLE Importer main | |
public static void main(String[] args) { | |
Importer importer = new Importer(args.length > 0 ? args[0] : "../repo/"); | |
importer.go(); | |
} | |
private void go() { | |
try { | |
File dir = new File(directory).getAbsoluteFile(); | |
doDir(dir); | |
} | |
catch (Throwable e) { | |
e.printStackTrace(out); | |
} | |
this.out.close(); | |
} | |
private void doDir(File dir) throws IOException, InterruptedException { | |
File[] listFiles = dir.listFiles(new PomFilter()); | |
if (listFiles != null) { | |
for (File pom : listFiles) { | |
doPom(pom); | |
} | |
} | |
File[] listDirs = dir.listFiles(new DirFilter()); | |
if (listDirs != null) { | |
for (File subdir : listDirs) { | |
doDir(subdir); | |
} | |
} | |
} | |
private void doPom(File pom) throws IOException, InterruptedException { | |
File base = pom.getParentFile(); | |
String fileName = pom.getName(); | |
String jarName = fileName.substring(0, fileName.length() - 3) + "jar"; | |
File jar = new File(base.getAbsolutePath() + "/" + jarName); | |
String exec = MVN_CLI | |
+ " deploy:deploy-file -DrepositoryId=" | |
+ REPO_ID | |
+ " -Durl=" + REPO_URL; | |
if (jar.exists()) { | |
exec += " -Dfile=\"" + jar.getAbsolutePath() + "\""; | |
} | |
else { | |
exec += " -Dfile=\"" + pom.getAbsolutePath() + "\""; | |
} | |
exec += " -DpomFile=\"" + pom.getAbsolutePath() + "\""; | |
exec(exec); | |
} | |
private void exec(String exec) throws InterruptedException, IOException { | |
out.println(exec); | |
} | |
private class PomFilter implements java.io.FileFilter { | |
@Override | |
public boolean accept(File pathname) { | |
return pathname.getName().endsWith(".pom"); | |
} | |
} | |
private class DirFilter implements java.io.FileFilter { | |
@Override | |
public boolean accept(File pathname) { | |
return pathname.isDirectory(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: http://www.devgrok.com/2012/01/bulk-upload-of-maven-artifacts-to.html