From: <mar...@us...> - 2017-02-02 13:00:35
|
Revision: 20062 http://sourceforge.net/p/gate/code/20062 Author: markagreenwood Date: 2017-02-02 13:00:32 +0000 (Thu, 02 Feb 2017) Log Message: ----------- when reloading a plugin via the persistence manager we now check to see if there is a cached copy of artifacts in maven-cache.gate relative to any of the file: URLS in the persistence stack Modified Paths: -------------- gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Plugin.java gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleMavenCache.java gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleModelResolver.java gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java Modified: gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Plugin.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Plugin.java 2017-02-02 12:59:12 UTC (rev 20061) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Plugin.java 2017-02-02 13:00:32 UTC (rev 20062) @@ -85,7 +85,9 @@ import gate.util.asm.Opcodes; import gate.util.asm.Type; import gate.util.asm.commons.EmptyVisitor; +import gate.util.maven.SimpleMavenCache; import gate.util.maven.SimpleModelResolver; +import gate.util.persistence.PersistenceManager; public abstract class Plugin { @@ -417,8 +419,6 @@ private String group, artifact, version; private transient URL artifactURL; - - private WorkspaceReader workspace = null;//new SimpleMavenCache(new File("cache")); public Maven(String group, String artifact, String version) { this.group = group; @@ -526,14 +526,39 @@ ArtifactRequest artifactRequest = new ArtifactRequest(artifactObj, repos, null); RepositorySystem repoSystem = getRepositorySystem(); + + WorkspaceReader workspace = null; + + List<URL> persistenceURLStack = PersistenceManager.currentPersistenceURLStack(); + + if (persistenceURLStack != null && !persistenceURLStack.isEmpty()) { + List<File> workspaces = new ArrayList<File>(); + + for (URL url : persistenceURLStack) { + try { + File file = gate.util.Files.fileFromURL(url); + File cache = new File(file.getParentFile(),"maven-cache.gate"); + System.out.println(cache.getAbsolutePath()); + if (cache.exists() && cache.isDirectory()) { + workspaces.add(cache); + } + } + catch (IllegalArgumentException e) { + //ignore this for now + } + } + + if (!workspaces.isEmpty()) { + workspace = new SimpleMavenCache(workspaces.toArray(new File[workspaces.size()])); + } + } + RepositorySystemSession repoSession = getRepositorySession(repoSystem, workspace); ArtifactResult artifactResult = repoSystem.resolveArtifact(repoSession, artifactRequest); - - //baseURL = new URI("creole://"+group+";"+artifact+";"+version+"/"); artifactURL = new URL("jar:" @@ -577,6 +602,9 @@ for(ArtifactResult ar : result.getArtifactResults()) { + log.info(ar.getArtifact().getFile().toURI().toURL() + .toExternalForm()); + Element jarElement = new Element("JAR"); jarElement.setText(ar.getArtifact().getFile().toURI().toURL() .toExternalForm()); Modified: gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleMavenCache.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleMavenCache.java 2017-02-02 12:59:12 UTC (rev 20061) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleMavenCache.java 2017-02-02 13:00:32 UTC (rev 20062) @@ -39,12 +39,16 @@ private transient WorkspaceRepository repo; - public SimpleMavenCache(File head, File... tail) { - this.head = head; + public SimpleMavenCache(File... dir) { + + if (dir == null || dir.length == 0) { + throw new NullPointerException("At least one workspace directory must be specified"); + } + + head = dir[0]; - if (tail.length > 0) { - this.tail = new SimpleMavenCache(tail[0], - tail.length == 1 ? new File[] {} : Arrays.copyOfRange(tail, 1, tail.length - 1)); + if (dir.length > 1) { + tail = new SimpleMavenCache(Arrays.copyOfRange(dir, 1, dir.length)); } } @@ -141,8 +145,8 @@ } Artifact artifactObj = new DefaultArtifact("uk.ac.gate.plugins", "annie", "jar", "9.0-SNAPSHOT"); - artifactObj = artifactObj.setFile( - new File("/home/mark/.m2/repository/uk/ac/gate/plugins/annie/9.0-SNAPSHOT/annie-9.0-SNAPSHOT.jar")); + //artifactObj = artifactObj.setFile( + // new File("/home/mark/.m2/repository/uk/ac/gate/plugins/annie/9.0-SNAPSHOT/annie-9.0-SNAPSHOT.jar")); SimpleMavenCache reader = new SimpleMavenCache(new File("repo")); System.out.println(reader.findArtifact(artifactObj)); Modified: gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleModelResolver.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleModelResolver.java 2017-02-02 12:59:12 UTC (rev 20061) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleModelResolver.java 2017-02-02 13:00:32 UTC (rev 20062) @@ -20,6 +20,7 @@ import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.resolution.ArtifactRequest; +@SuppressWarnings("deprecation") public class SimpleModelResolver implements ModelResolver { private final RepositorySystem system; Modified: gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java 2017-02-02 12:59:12 UTC (rev 20061) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java 2017-02-02 13:00:32 UTC (rev 20062) @@ -36,6 +36,7 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -1167,9 +1168,13 @@ /** * Get the file currently being saved by this thread. */ - private static File currentPersistenceFile() { + public static File currentPersistenceFile() { return persistenceFile.get().getFirst(); } + + public static List<File> currentPersistenceFileStack() { + return Collections.unmodifiableList(persistenceFile.get()); + } private static Boolean currentWarnAboutGateHome() { return warnAboutGateHome.get().getFirst(); @@ -1358,9 +1363,13 @@ /** * Get the URL currently being loaded by this thread. */ - private static URL currentPersistenceURL() { + public static URL currentPersistenceURL() { return persistenceURL.get().getFirst(); } + + public static List<URL> currentPersistenceURLStack() { + return Collections.unmodifiableList(persistenceURL.get()); + } /** * Clean up the thread-local state at the end of a loading run. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |