Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
bz-1004246: Location of busineess central maven repo dir should be co…
Browse files Browse the repository at this point in the history
…nfigurable
  • Loading branch information
jervisliu committed Sep 24, 2013
1 parent a7184d6 commit 8d9abac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Expand Up @@ -64,6 +64,7 @@ public class GuvnorM2Repository {
private static final Logger log = LoggerFactory.getLogger(GuvnorM2Repository.class);

public static final String M2_REPO_ROOT = "repository";
public static String M2_REPO_DIR;
public static final String REPO_ID_SNAPSHOTS = "snapshots";
public static final String REPO_ID_RELEASES = "releases";
private static final int BUFFER_SIZE = 1024;
Expand All @@ -77,6 +78,14 @@ protected void init() {
}

private void setM2Repos() {
final String meReposDir = System.getProperty( "org.guvnor.m2repo.dir" );

if ( meReposDir == null || meReposDir.trim().isEmpty() ) {
M2_REPO_DIR = M2_REPO_ROOT;
} else {
M2_REPO_DIR = meReposDir.trim();
}

snapshotsRepository = new File(getM2RepositoryRootDir() + File.separator + REPO_ID_SNAPSHOTS);
if (!snapshotsRepository.exists()) {
snapshotsRepository.mkdirs();
Expand All @@ -89,10 +98,10 @@ private void setM2Repos() {
}

protected String getM2RepositoryRootDir() {
if (!M2_REPO_ROOT.endsWith(File.separator)) {
return M2_REPO_ROOT + File.separator;
if (!M2_REPO_DIR.endsWith(File.separator)) {
return M2_REPO_DIR + File.separator;
} else {
return M2_REPO_ROOT;
return M2_REPO_DIR;
}
}

Expand Down Expand Up @@ -181,7 +190,7 @@ public void deployArtifact(GAV gav, File jarFile, File pomfile) {
}

private RemoteRepository getGuvnorM2Repository() {
File m2RepoDir = new File( M2_REPO_ROOT );
File m2RepoDir = new File( M2_REPO_DIR );
if (!m2RepoDir.exists()) {
return null;
}
Expand All @@ -194,7 +203,7 @@ private RemoteRepository getGuvnorM2Repository() {

public boolean deleteFile(String[] fullPaths) {
for (String fullPath : fullPaths) {
final File file = new File(M2_REPO_ROOT, fullPath);
final File file = new File(M2_REPO_DIR, fullPath);
if (file.exists()) {
file.delete();
}
Expand Down Expand Up @@ -224,7 +233,7 @@ public Collection<File> listFiles(String filters) {
wildcard = "*" + filters + "*.jar";
}
Collection<File> files = FileUtils.listFiles(
new File(M2_REPO_ROOT),
new File(M2_REPO_DIR),
new WildcardFileFilter(wildcard, IOCase.INSENSITIVE),
DirectoryFileFilter.DIRECTORY
);
Expand All @@ -234,19 +243,19 @@ public Collection<File> listFiles(String filters) {

public InputStream loadFile(String path) {
try {
return new FileInputStream(new File(M2_REPO_ROOT, path));
return new FileInputStream(new File(M2_REPO_DIR, path));
} catch (FileNotFoundException e) {
log.error(e.getMessage());
}
return null;
}

public String getFileName(String path) {
return (new File(M2_REPO_ROOT, path)).getName();
return (new File(M2_REPO_DIR, path)).getName();
}

public static String loadPOMFromJar(String jarPath) {
File zip = new File(M2_REPO_ROOT, jarPath);
File zip = new File(M2_REPO_DIR, jarPath);

return loadPOMFromJarInternal(zip);
}
Expand Down
Expand Up @@ -103,7 +103,7 @@ public PageResponse<JarListPageRow> listJars( PageRequest pageRequest,
JarListPageRow jarListPageRow = new JarListPageRow();
jarListPageRow.setName( file.getName() );
//stripe the prefix of "repository"
String jarPath = file.getPath().substring( GuvnorM2Repository.M2_REPO_ROOT.length() + 1 );
String jarPath = file.getPath().substring( GuvnorM2Repository.M2_REPO_DIR.length() + 1 );
jarListPageRow.setPath( jarPath );
jarListPageRow.setLastModified( new Date( file.lastModified() ) );
tradeRatePageRowList.add( jarListPageRow );
Expand Down

0 comments on commit 8d9abac

Please sign in to comment.