Revision: 19455
http://sourceforge.net/p/gate/code/19455
Author: markagreenwood
Date: 2016-07-07 08:39:07 +0000 (Thu, 07 Jul 2016)
Log Message:
-----------
merged in Richard's patch so we pull in config from the users existing maven
settings.xml if present
Modified Paths:
--------------
gate/branches/sawdust2/pom.xml
gate/branches/sawdust2/src/main/java/gate/Plugin.java
Modified: gate/branches/sawdust2/pom.xml
===================================================================
--- gate/branches/sawdust2/pom.xml 2016-07-07 01:23:17 UTC (rev 19454)
+++ gate/branches/sawdust2/pom.xml 2016-07-07 08:39:07 UTC (rev 19455)
@@ -139,6 +139,23 @@
<scope>compile</scope>
</dependency>
+ <!-- - If this is omitted, we somehow get a
ClassNotFoundException for -
+ org.codehaus.plexus.util.xml.pull.EntityReplacementMap
despite the - dependency
+ appearing with scope compile in the dependency
hierarchy... -->
+ <!-- <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.22</version>
+ <scope>compile</scope>
+ </dependency> -->
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-settings-builder</artifactId>
+ <version>3.3.9</version>
+ <scope>compile</scope>
+ </dependency>
+
<!-- needed to ensure the same version across configurations -->
<dependency>
<groupId>commons-logging</groupId>
Modified: gate/branches/sawdust2/src/main/java/gate/Plugin.java
===================================================================
--- gate/branches/sawdust2/src/main/java/gate/Plugin.java 2016-07-07
01:23:17 UTC (rev 19454)
+++ gate/branches/sawdust2/src/main/java/gate/Plugin.java 2016-07-07
08:39:07 UTC (rev 19455)
@@ -22,6 +22,15 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.apache.maven.settings.Profile;
+import org.apache.maven.settings.Repository;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.building.DefaultSettingsBuilder;
+import org.apache.maven.settings.building.DefaultSettingsBuilderFactory;
+import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
+import org.apache.maven.settings.building.SettingsBuildingException;
+import org.apache.maven.settings.building.SettingsBuildingRequest;
+import org.apache.maven.settings.building.SettingsBuildingResult;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
@@ -359,7 +368,26 @@
public static class Maven extends Plugin implements Serializable {
private static final long serialVersionUID = -6944695755723023537L;
+
+ public static final String userHome = System.getProperty("user.home");
+ public static final File userMavenConfigurationHome =
+ new File(userHome, ".m2");
+
+ public static final String envM2Home = System.getenv("M2_HOME");
+
+ public static final File DEFAULT_USER_SETTINGS_FILE =
+ new File(userMavenConfigurationHome, "settings.xml");
+
+ public static final String settingsXml = System.getProperty(
+ "M2_SETTINGS_XML", DEFAULT_USER_SETTINGS_FILE.getPath());
+
+ public static final File DEFAULT_GLOBAL_SETTINGS_FILE =
+ new File(
+ System.getProperty("maven.home",
+ envM2Home != null ? envM2Home : ""),
+ "conf/settings.xml");
+
private String group, artifact, version;
public Maven(String group, String artifact, String version) {
@@ -368,9 +396,7 @@
this.version = version;
//TODO move calculation of baseURL into here
- }
-
-
+ }
@Override
public int hashCode() {
@@ -382,8 +408,6 @@
return result;
}
-
-
@Override
public boolean equals(Object obj) {
if(this == obj) return true;
@@ -402,8 +426,27 @@
return true;
}
+ private static Settings loadMavenSettings() throws
SettingsBuildingException {
+ //
http://stackoverflow.com/questions/27818659/loading-mavens-settings-xml-for-jcabi-aether-to-use
+ SettingsBuildingRequest settingsBuildingRequest =
+ new DefaultSettingsBuildingRequest();
+ settingsBuildingRequest.setSystemProperties(System.getProperties());
+ settingsBuildingRequest.setUserSettingsFile(new File(settingsXml));
+ settingsBuildingRequest
+ .setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE);
+ SettingsBuildingResult settingsBuildingResult;
+ DefaultSettingsBuilderFactory mvnSettingBuilderFactory =
+ new DefaultSettingsBuilderFactory();
+ DefaultSettingsBuilder settingsBuilder =
+ mvnSettingBuilderFactory.newInstance();
+ settingsBuildingResult = settingsBuilder.build(settingsBuildingRequest);
+ Settings effectiveSettings =
+ settingsBuildingResult.getEffectiveSettings();
+ return effectiveSettings;
+ }
+
@Override
public Document getCreoleXML() throws Exception {
Artifact artifactObj =
@@ -417,6 +460,21 @@
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifactObj);
artifactRequest.addRepository(central);
+
+ // Add all repos from settings.xml
+ //
http://stackoverflow.com/questions/27818659/loading-mavens-settings-xml-for-jcabi-aether-to-use
+ Settings effectiveSettings = loadMavenSettings();
+ Map<String, Profile> profilesMap = effectiveSettings.getProfilesAsMap();
+ for(String profileName : effectiveSettings.getActiveProfiles()) {
+ Profile profile = profilesMap.get(profileName);
+ List<Repository> repositories = profile.getRepositories();
+ for(Repository repo : repositories) {
+ RemoteRepository remoteRepo =
+ new RemoteRepository.Builder(repo.getId(), "default",
+ repo.getUrl()).build();
+ artifactRequest.addRepository(remoteRepo);
+ }
+ }
ArtifactResult artifactResult =
getRepositorySystem().resolveArtifact(getRepositorySession(),
@@ -502,12 +560,26 @@
repoSystemSession = MavenRepositorySystemUtils.newSession();
- //TODO pull this from the maven settings.xml file
- LocalRepository localRepo =
- new
LocalRepository(System.getProperty("user.home")+File.separator+".m2"+File.separator+"repository/");
- System.out.println(localRepo);
+ String repoLocation = System.getProperty("user.home") + File.separator
+ + ".m2" + File.separator + "repository/";
+ try {
+ Settings effectiveSettings = loadMavenSettings();
+ if(effectiveSettings.getLocalRepository() != null) {
+ repoLocation = effectiveSettings.getLocalRepository();
+ }
+ } catch(Exception e) {
+ log.warn(
+ "Unable to load Maven settings, using default repository
location",
+ e);
+ }
+
+ LocalRepository localRepo = new LocalRepository(repoLocation);
+ log.info("Using local repository at: " + repoLocation);
repoSystemSession.setLocalRepositoryManager(getRepositorySystem()
.newLocalRepositoryManager(repoSystemSession, localRepo));
+
+ repoSystemSession.setLocalRepositoryManager(getRepositorySystem()
+ .newLocalRepositoryManager(repoSystemSession, localRepo));
return repoSystemSession;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs