Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Let's not create a cache folder to know where to place the cache folder please, just so we don't
have to move two functions.
  • Loading branch information
FroMage committed Apr 15, 2015
1 parent da9a545 commit 53aea05
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 56 deletions.
16 changes: 0 additions & 16 deletions api/src/main/java/com/redhat/ceylon/cmr/api/RepositoryBuilder.java
Expand Up @@ -30,20 +30,4 @@ public interface RepositoryBuilder {
* @throws Exception for any error
*/
Repository buildRepository(String token) throws Exception;

/**
* Is remote.
*
* @param token the token
* @return true if token represents remote repo, false otherwise
*/
boolean isRemote(String token);

/**
* Is HTTP.
*
* @param token the token
* @return true if token represents http backed repo, false otherwise
*/
boolean isHttp(String token);
}
39 changes: 18 additions & 21 deletions ceylon/src/main/java/com/redhat/ceylon/cmr/ceylon/CeylonUtils.java
Expand Up @@ -2,6 +2,8 @@

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -50,7 +52,6 @@ public static class CeylonRepoManagerBuilder {
private boolean noDefRepos;
private boolean jdkIncluded;
private Logger log;
private RepositoryBuilder throwawayRB;

/**
* Sets the configuration to use for building the repository manager
Expand Down Expand Up @@ -467,7 +468,7 @@ public RepositoryManager buildOutputManager() {
outRepo = temp;
}

if (!isHTTP(outRepo)) {
if (!isHttp(outRepo)) {
File repoFolder = new File(absolute(outRepo));
if (repoFolder.exists()) {
if (!repoFolder.isDirectory()) {
Expand Down Expand Up @@ -550,25 +551,6 @@ private String absolute(String path) {
return prefix + path;
}

private synchronized RepositoryBuilder getThrowawayRB() {
if (throwawayRB == null) {
Logger logger = log;
if (logger == null) {
logger = new CMRJULLogger();
}
throwawayRB = new RepositoryManagerBuilder(logger).repositoryBuilder();
}
return throwawayRB;
}

private boolean isHTTP(String repo) {
return getThrowawayRB().isHttp(repo);
}

private boolean isRemote(String repo) {
return getThrowawayRB().isRemote(repo);
}

private boolean isOffline(CeylonConfig config) {
return offline || DefaultToolOptions.getDefaultOffline(config);
}
Expand Down Expand Up @@ -638,5 +620,20 @@ public static <T> boolean arrayContains(T[] array, T item) {
return Arrays.asList(array).contains(item);
}

public static boolean isRemote(String token) {
// IMPORTANT Make sure this is consistent with RepositoryBuilderImpl.buildRepository() !
// (except for "file:" which we don't support)
return isHttp(token) || "mvn".equals(token) || token.startsWith("mvn:") || "aether".equals(token) || token.startsWith("aether:") || token.equals("jdk") || token.equals("jdk:");
}

public static boolean isHttp(String token) {
try {
URL url = new URL(token);
String protocol = url.getProtocol();
return "http".equals(protocol) || "https".equals(protocol);
} catch (MalformedURLException e) {
return false;
}
}
}

Expand Up @@ -19,14 +19,12 @@

import java.io.File;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

import com.redhat.ceylon.common.log.Logger;
import com.redhat.ceylon.cmr.api.Repository;
import com.redhat.ceylon.cmr.api.RepositoryBuilder;
import com.redhat.ceylon.cmr.spi.StructureBuilder;
import com.redhat.ceylon.common.log.Logger;

/**
* Repository builder.
Expand Down Expand Up @@ -102,20 +100,4 @@ protected Repository createMavenRepository(String token, String prefix) throws E
Method createRepository = aetherRepositoryClass.getMethod("createRepository", Logger.class, String.class, boolean.class, int.class);
return (Repository) createRepository.invoke(null, log, settingsXml, offline, timeout);
}

public boolean isRemote(String token) {
// IMPORTANT Make sure this is consistent with RepositoryBuilderImpl.buildRepository() !
// (except for "file:" which we don't support)
return isHttp(token) || "mvn".equals(token) || token.startsWith("mvn:") || "aether".equals(token) || token.startsWith("aether:") || token.equals("jdk") || token.equals("jdk:");
}

public boolean isHttp(String token) {
try {
URL url = new URL(token);
String protocol = url.getProtocol();
return "http".equals(protocol) || "https".equals(protocol);
} catch (MalformedURLException e) {
return false;
}
}
}

0 comments on commit 53aea05

Please sign in to comment.