Author: fbricon
Date: 2012-08-28 05:34:41 -0400 (Tue, 28 Aug 2012)
New Revision: 43261
Added:
trunk/maven/plugins/org.jboss.tools.maven.core/.settings/org.eclipse.m2e.core.prefs
trunk/maven/plugins/org.jboss.tools.maven.core/lib/
trunk/maven/plugins/org.jboss.tools.maven.core/lib/nexus-indexer-lucene-rest-api-client.jar
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/AbstractArtifactIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/repositories/
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/repositories/NexusRepository.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/repositories/RemoteRepositoryManager.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/repositories/
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/repositories/EditNexusRepositoryDialog.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/preferences/AutoResizeTableLayout.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/preferences/RemoteRepositoriesPreferencePage.java
Removed:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/lib/
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/NexusRepository.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/browsers/EditNexusRepositoryDialog.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/AutoResizeTableLayout.java
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/IdentifyJarJob.java
trunk/maven/plugins/org.jboss.tools.maven.core/.classpath
trunk/maven/plugins/org.jboss.tools.maven.core/.project
trunk/maven/plugins/org.jboss.tools.maven.core/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.core/build.properties
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/MavenCoreActivator.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/ArtifactIdentifier.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/IFileIdentificationManager.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/IdentificationUtil.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/.classpath
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/SourceLookupActivator.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/containers/JBossSourceContainer.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/actions/AttachSourcesActionDelegate.java
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/SourceLookupPreferencePage.java
trunk/maven/plugins/org.jboss.tools.maven.ui/.settings/org.eclipse.jdt.core.prefs
trunk/maven/plugins/org.jboss.tools.maven.ui/.settings/org.eclipse.m2e.core.prefs
trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/ConfigureMavenRepositoriesWizardPage.java
Log:
JBIDE-12314 : move all the identification and remote repository management parts to the
maven core/ui plugins.
Modified: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF 2012-08-28
09:34:41 UTC (rev 43261)
@@ -12,8 +12,8 @@
org.eclipse.core.resources,
org.eclipse.jst.j2ee.ui;bundle-version="1.1.500",
org.eclipse.ui.ide;bundle-version="3.7.0",
- org.jboss.tools.maven.sourcelookup.core;bundle-version="1.4.0",
- org.eclipse.m2e.core.ui;bundle-version="1.1.0"
+ org.eclipse.m2e.core.ui;bundle-version="1.1.0",
+ org.jboss.tools.maven.core;bundle-version="1.4.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: %BundleVendor
Bundle-Localization: plugin
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -57,9 +57,9 @@
import org.jboss.tools.maven.conversion.ui.handlers.IdentifyJarJob;
import org.jboss.tools.maven.conversion.ui.internal.CellListener;
import org.jboss.tools.maven.conversion.ui.internal.MavenDependencyConversionActivator;
-import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
-import org.jboss.tools.maven.sourcelookup.identification.IdentificationUtil;
-import
org.jboss.tools.maven.sourcelookup.internal.identification.FileIdentificationManager;
+import org.jboss.tools.maven.core.identification.IFileIdentificationManager;
+import org.jboss.tools.maven.core.identification.IdentificationUtil;
+import org.jboss.tools.maven.core.internal.identification.FileIdentificationManager;
public class IdentifyMavenDependencyPage extends WizardPage {
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/IdentifyJarJob.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/IdentifyJarJob.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/IdentifyJarJob.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -10,7 +10,7 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.jboss.tools.maven.conversion.ui.internal.MavenDependencyConversionActivator;
-import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
+import org.jboss.tools.maven.core.identification.IFileIdentificationManager;
public class IdentifyJarJob extends Job {
Modified: trunk/maven/plugins/org.jboss.tools.maven.core/.classpath
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.core/.classpath 2012-08-28 01:09:13 UTC (rev
43260)
+++ trunk/maven/plugins/org.jboss.tools.maven.core/.classpath 2012-08-28 09:34:41 UTC (rev
43261)
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry exported="true" kind="lib"
path="lib/nexus-indexer-lucene-rest-api-client.jar"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src/"/>
+ <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Modified: trunk/maven/plugins/org.jboss.tools.maven.core/.project
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.core/.project 2012-08-28 01:09:13 UTC (rev
43260)
+++ trunk/maven/plugins/org.jboss.tools.maven.core/.project 2012-08-28 09:34:41 UTC (rev
43261)
@@ -1,34 +1,40 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.jboss.tools.maven.core</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.maven.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
Added:
trunk/maven/plugins/org.jboss.tools.maven.core/.settings/org.eclipse.m2e.core.prefs
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.core/.settings/org.eclipse.m2e.core.prefs
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/.settings/org.eclipse.m2e.core.prefs 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
Modified: trunk/maven/plugins/org.jboss.tools.maven.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.core/META-INF/MANIFEST.MF 2012-08-28
01:09:13 UTC (rev 43260)
+++ trunk/maven/plugins/org.jboss.tools.maven.core/META-INF/MANIFEST.MF 2012-08-28
09:34:41 UTC (rev 43261)
@@ -32,6 +32,11 @@
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: %Bundle-Vendor
Export-Package: org.jboss.tools.maven.core,
+ org.jboss.tools.maven.core.identification,
+
org.jboss.tools.maven.core.internal.identification;x-friends:="org.jboss.tools.maven.common.test",
org.jboss.tools.maven.core.internal.project.facet,
org.jboss.tools.maven.core.libprov,
+ org.jboss.tools.maven.core.repositories,
org.jboss.tools.maven.core.xpl
+Bundle-ClassPath: lib/nexus-indexer-lucene-rest-api-client.jar,
+ .
Modified: trunk/maven/plugins/org.jboss.tools.maven.core/build.properties
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.core/build.properties 2012-08-28 01:09:13
UTC (rev 43260)
+++ trunk/maven/plugins/org.jboss.tools.maven.core/build.properties 2012-08-28 09:34:41
UTC (rev 43261)
@@ -5,4 +5,5 @@
plugin.xml,\
poms/,\
plugin.properties,\
- about.html
+ about.html,\
+ lib/nexus-indexer-lucene-rest-api-client.jar
Added:
trunk/maven/plugins/org.jboss.tools.maven.core/lib/nexus-indexer-lucene-rest-api-client.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/maven/plugins/org.jboss.tools.maven.core/lib/nexus-indexer-lucene-rest-api-client.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/MavenCoreActivator.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/MavenCoreActivator.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/MavenCoreActivator.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -41,6 +41,8 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jdt.core.IClasspathAttribute;
@@ -70,7 +72,9 @@
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.jboss.tools.maven.core.repositories.RemoteRepositoryManager;
import org.osgi.framework.BundleContext;
+import org.osgi.service.prefs.BackingStoreException;
/**
* The activator class controls the plug-in life cycle
@@ -101,6 +105,8 @@
private static PomResourceImpl resource;
+ private RemoteRepositoryManager repositoryManager;
+
/**
* The constructor
*/
@@ -745,4 +751,27 @@
}
}
+
+ public RemoteRepositoryManager getRepositoryManager() {
+ if (repositoryManager == null) {
+ repositoryManager = new RemoteRepositoryManager();
+ }
+ return repositoryManager;
+ }
+
+ public static IEclipsePreferences getPreferences() {
+ IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(PLUGIN_ID);
+ return prefs;
+ }
+
+ public void savePreferences() {
+ IEclipsePreferences prefs = getPreferences();
+ try {
+ prefs.flush();
+ } catch (BackingStoreException e) {
+ log(e);
+ }
+ }
+
+
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/ArtifactIdentifier.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/ArtifactIdentifier.java 2012-08-23
06:59:05 UTC (rev 43185)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/ArtifactIdentifier.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -8,7 +8,7 @@
* Contributors:
* JBoss by Red Hat - Initial implementation.
************************************************************************************/
-package org.jboss.tools.maven.sourcelookup.identification;
+package org.jboss.tools.maven.core.identification;
import java.io.File;
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/IFileIdentificationManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IFileIdentificationManager.java 2012-08-23
06:59:05 UTC (rev 43185)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/IFileIdentificationManager.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -8,7 +8,7 @@
* Contributors:
* JBoss by Red Hat - Initial implementation.
************************************************************************************/
-package org.jboss.tools.maven.sourcelookup.identification;
+package org.jboss.tools.maven.core.identification;
import java.io.File;
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/IdentificationUtil.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/identification/IdentificationUtil.java 2012-08-23
06:59:05 UTC (rev 43185)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/identification/IdentificationUtil.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -8,7 +8,7 @@
* Contributors:
* JBoss by Red Hat - Initial implementation.
************************************************************************************/
-package org.jboss.tools.maven.sourcelookup.identification;
+package org.jboss.tools.maven.core.identification;
import java.io.File;
import java.io.FileInputStream;
@@ -27,7 +27,9 @@
public static String getSHA1(File file) throws IOException,
NoSuchAlgorithmException {
-
+ if (file == null) {
+ return null;
+ }
InputStream inputStream = null;
StringBuilder sb = new StringBuilder();
try {
Copied:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/AbstractArtifactIdentifier.java
(from rev 43221,
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/AbstractArtifactIdentifier.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/AbstractArtifactIdentifier.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/AbstractArtifactIdentifier.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,40 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.core.internal.identification;
+
+import org.jboss.tools.maven.core.identification.ArtifactIdentifier;
+
+abstract class AbstractArtifactIdentifier implements ArtifactIdentifier {
+
+ private String name;
+
+ AbstractArtifactIdentifier() {
+ }
+
+ AbstractArtifactIdentifier(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ if (name == null) {
+ name = getClass().getSimpleName();
+ }
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String toString() {
+ return (name == null)? super.toString():name;
+ }
+}
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/FileIdentificationManager.java 2012-08-23
06:59:05 UTC (rev 43185)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -1,62 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2008-2012 Red Hat, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- *
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * JBoss by Red Hat - Initial implementation.
- ************************************************************************************/
-package org.jboss.tools.maven.sourcelookup.internal.identification;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.m2e.core.embedder.ArtifactKey;
-import org.jboss.tools.maven.sourcelookup.identification.ArtifactIdentifier;
-import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
-
-/**
- *
- * @author Fred Bricon
- *
- */
-public class FileIdentificationManager implements IFileIdentificationManager {
-
- private List<ArtifactIdentifier> artifactIdentifiers;
-
- public FileIdentificationManager() {
- initArtifactIdentifiers();
- }
-
- private void initArtifactIdentifiers() {
- //TODO read from extension points?
- artifactIdentifiers = new ArrayList<ArtifactIdentifier>(3);
- artifactIdentifiers.add(new MavenPropertiesIdentifier());
- artifactIdentifiers.add(new NexusIndexIdentifier());
- artifactIdentifiers.add(new NexusRepositoryIdentifier());
- }
-
- @Override
- public ArtifactKey identify(File file, IProgressMonitor monitor) throws CoreException {
- ArtifactKey artifactKey = null;
- long start = System.currentTimeMillis();
- for (ArtifactIdentifier identifier : artifactIdentifiers) {
- if (monitor.isCanceled()) {
- return null;
- }
- artifactKey = identifier.identify(file);
- if (artifactKey != null) {
- long stop = System.currentTimeMillis();
- System.err.println(file.getName() + " identified as " + artifactKey +
" in " + (stop-start) + " ms");
- break;
- }
- }
- return artifactKey;
- }
-
-}
Copied:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java
(from rev 43221,
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/FileIdentificationManager.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/FileIdentificationManager.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,100 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.core.internal.identification;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.jboss.tools.maven.core.identification.ArtifactIdentifier;
+import org.jboss.tools.maven.core.identification.IFileIdentificationManager;
+
+/**
+ *
+ * @author Fred Bricon
+ *
+ */
+public class FileIdentificationManager implements IFileIdentificationManager {
+
+ private List<ArtifactIdentifier> artifactIdentifiers;
+
+ public FileIdentificationManager() {
+ initArtifactIdentifiers();
+ }
+
+ public FileIdentificationManager(Collection<ArtifactIdentifier> identifiers) {
+ for (ArtifactIdentifier identifier : identifiers) {
+ addArtifactIdentifier(identifier);
+ }
+ }
+
+ protected void initArtifactIdentifiers() {
+ //TODO read from extension points?
+ addArtifactIdentifier(new MavenPropertiesIdentifier());
+ addArtifactIdentifier(new NexusIndexIdentifier());
+ addArtifactIdentifier(new NexusRepositoryIdentifier());
+ }
+
+ public synchronized void addArtifactIdentifier(ArtifactIdentifier identifier) {
+ Assert.isNotNull(identifier, "Artifact identifier can not be null");
+ if (artifactIdentifiers == null) {
+ artifactIdentifiers = new ArrayList<ArtifactIdentifier>();
+ }
+ artifactIdentifiers.add(identifier);
+ //System.err.println("Added "+ identifier);
+ }
+
+ public synchronized void removeArtifactIdentifier(ArtifactIdentifier identifier) {
+ if (identifier != null) {
+ getArtifactIdentifiers().remove(identifier);
+ }
+ }
+
+ protected List<ArtifactIdentifier> getArtifactIdentifiers() {
+ if (artifactIdentifiers == null) {
+ initArtifactIdentifiers();
+ }
+ return artifactIdentifiers;
+ }
+
+ public ArtifactKey identify(File file, IProgressMonitor monitor) throws CoreException {
+ if (file == null) {
+ return null;
+ }
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ ArtifactKey artifactKey = null;
+ //long start = System.currentTimeMillis();
+ for (ArtifactIdentifier identifier : artifactIdentifiers) {
+ if (monitor.isCanceled()) {
+ return null;
+ }
+ artifactKey = identifier.identify(file);
+ if (artifactKey != null) {
+ //long stop = System.currentTimeMillis();
+ //System.err.println(file.getName() + " identified as " + artifactKey +
" in " + (stop-start) + " ms");
+ break;
+ }
+ }
+ //if (artifactKey == null)
+ //System.err.println("Could not identify "+file);
+ return artifactKey;
+ }
+
+
+}
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/MavenPropertiesIdentifier.java 2012-08-23
06:59:05 UTC (rev 43185)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -1,72 +0,0 @@
-package org.jboss.tools.maven.sourcelookup.internal.identification;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Properties;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-import java.util.zip.ZipFile;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.m2e.core.embedder.ArtifactKey;
-import org.jboss.tools.maven.sourcelookup.identification.ArtifactIdentifier;
-
-public class MavenPropertiesIdentifier implements ArtifactIdentifier {
-
- @Override
- public ArtifactKey identify(File file) throws CoreException {
- ZipFile jar;
- try {
-// try {
-// Random r = new Random();
-// Thread.sleep(r.nextInt(10)*1000);
-// } catch (InterruptedException e) {
-// }
- jar = new ZipFile(file);
- return getArtifactFromMetaInf(jar);
- } catch (ZipException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- protected static ArtifactKey getArtifactFromMetaInf(ZipFile jar) throws IOException {
- ZipEntry mavenEntry = jar.getEntry("META-INF/maven");//$NON-NLS-1$
- if (mavenEntry == null) {
- return null;
- }
- String entryName = mavenEntry.getName();
- Enumeration<? extends ZipEntry> zipEntries = jar.entries();
- ArtifactKey artifact = null;
-
-
- while (zipEntries.hasMoreElements()) {
- ZipEntry zipEntry = zipEntries.nextElement();
- if (zipEntry.getName().endsWith("pom.properties")
- && zipEntry.getName().startsWith(entryName)) {
- if (artifact != null) {
- //org.fusesource.jansi:jansi:1.6 is an OSGi bundle containing several maven pom
files.
- //The first properties being found is wrong.
- //So for the moment we bail but should try to look at the MANIFEST.MF
- return null;
- }
- Properties props = new Properties();
- props.load(jar.getInputStream(zipEntry));
- String groupId = props.getProperty("groupId");
- String artifactId = props.getProperty("artifactId");
- String version = props.getProperty("version");
- String classifier = props.getProperty("classifier");
- if (groupId != null && artifactId != null && version != null) {
- artifact = new ArtifactKey(groupId, artifactId, version,
- classifier);
- }
- }
- }
-
- return artifact;
- }
-}
Copied:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java
(from rev 43221,
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/MavenPropertiesIdentifier.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/MavenPropertiesIdentifier.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,79 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.core.internal.identification;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+
+public class MavenPropertiesIdentifier extends AbstractArtifactIdentifier {
+
+ public MavenPropertiesIdentifier() {
+ super("Maven Properties identifier");
+ }
+
+ public ArtifactKey identify(File file) throws CoreException {
+ ZipFile jar;
+ try {
+ jar = new ZipFile(file);
+ return getArtifactFromMetaInf(jar);
+ } catch (ZipException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ //System.err.println(getName() + " could not identify "+file);
+ return null;
+ }
+
+ protected static ArtifactKey getArtifactFromMetaInf(ZipFile jar) throws IOException {
+ ZipEntry mavenEntry = jar.getEntry("META-INF/maven");//$NON-NLS-1$
+ if (mavenEntry == null) {
+ return null;
+ }
+ String entryName = mavenEntry.getName();
+ Enumeration<? extends ZipEntry> zipEntries = jar.entries();
+ ArtifactKey artifact = null;
+
+
+ while (zipEntries.hasMoreElements()) {
+ ZipEntry zipEntry = zipEntries.nextElement();
+ if (zipEntry.getName().endsWith("pom.properties")
+ && zipEntry.getName().startsWith(entryName)) {
+ if (artifact != null) {
+ //org.fusesource.jansi:jansi:1.6 is an OSGi bundle containing several maven pom
files.
+ //The first properties being found is wrong.
+ //So for the moment we bail but should try to look at the MANIFEST.MF
+ return null;
+ }
+ Properties props = new Properties();
+ props.load(jar.getInputStream(zipEntry));
+ String groupId = props.getProperty("groupId");
+ String artifactId = props.getProperty("artifactId");
+ String version = props.getProperty("version");
+ String classifier = props.getProperty("classifier");
+ if (groupId != null && artifactId != null && version != null) {
+ artifact = new ArtifactKey(groupId, artifactId, version,
+ classifier);
+ }
+ }
+ }
+
+ return artifact;
+ }
+}
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusIndexIdentifier.java 2012-08-23
06:59:05 UTC (rev 43185)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -1,74 +0,0 @@
-package org.jboss.tools.maven.sourcelookup.internal.identification;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.embedder.ArtifactKey;
-import org.eclipse.m2e.core.internal.index.IIndex;
-import org.eclipse.m2e.core.internal.index.IndexManager;
-import org.eclipse.m2e.core.internal.index.IndexedArtifactFile;
-import org.eclipse.m2e.core.internal.index.nexus.NexusIndex;
-import org.eclipse.m2e.core.internal.index.nexus.NexusIndexManager;
-import org.eclipse.m2e.core.repository.IRepository;
-import org.eclipse.m2e.core.repository.IRepositoryRegistry;
-import org.jboss.tools.maven.sourcelookup.identification.ArtifactIdentifier;
-
-@SuppressWarnings("restriction")
-public class NexusIndexIdentifier implements ArtifactIdentifier {
-
- private List<IRepository> globalRepositories;
-
- public NexusIndexIdentifier() {
- globalRepositories = initGlobalRepositories();
- }
-
- @Override
- public ArtifactKey identify(File file) throws CoreException {
- IndexManager indexManager = MavenPlugin.getIndexManager();
- IIndex index = indexManager.getAllIndexes();
- IndexedArtifactFile info = null;
- try {
- info = index.identify(file);
- } catch (Throwable e) {
- // ignore
- }
- ArtifactKey artifact = null;
- if (info != null) {
- artifact = info.getArtifactKey();
- if (artifact != null) {
- return artifact;
- }
- }
- if (indexManager instanceof NexusIndexManager) {
- NexusIndexManager nexusIndexManager = (NexusIndexManager) indexManager;
- for (IRepository repository : globalRepositories) {
- NexusIndex nexusIndex = nexusIndexManager.getIndex(repository);
- if (nexusIndex != null) {
- try {
- info = nexusIndex.identify(file);
- } catch (Throwable t) {
- // ignore
- }
- if (info != null) {
- artifact = info.getArtifactKey();
- if (artifact != null) {
- return artifact;
- }
- }
- }
- }
- }
- return artifact;
- }
-
- private List<IRepository> initGlobalRepositories() {
- IRepositoryRegistry repositoryRegistry = MavenPlugin.getRepositoryRegistry();
- List<IRepository> repositories = repositoryRegistry.
- getRepositories(IRepositoryRegistry.SCOPE_SETTINGS);
- return repositories == null? Collections.<IRepository>emptyList():repositories;
- }
-
-}
Copied:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java
(from rev 43221,
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusIndexIdentifier.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusIndexIdentifier.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,84 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.core.internal.identification;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.eclipse.m2e.core.internal.index.IIndex;
+import org.eclipse.m2e.core.internal.index.IndexManager;
+import org.eclipse.m2e.core.internal.index.IndexedArtifactFile;
+import org.eclipse.m2e.core.internal.index.nexus.NexusIndex;
+import org.eclipse.m2e.core.internal.index.nexus.NexusIndexManager;
+import org.eclipse.m2e.core.repository.IRepository;
+import org.eclipse.m2e.core.repository.IRepositoryRegistry;
+
+@SuppressWarnings("restriction")
+public class NexusIndexIdentifier extends AbstractArtifactIdentifier {
+
+ private List<IRepository> globalRepositories;
+
+ public NexusIndexIdentifier() {
+ super("Nexus Index identifier");
+ globalRepositories = initGlobalRepositories();
+ }
+
+ public ArtifactKey identify(File file) throws CoreException {
+ IndexManager indexManager = MavenPlugin.getIndexManager();
+ IIndex index = indexManager.getAllIndexes();
+ IndexedArtifactFile info = null;
+ try {
+ info = index.identify(file);
+ } catch (Throwable e) {
+ // ignore
+ }
+ ArtifactKey artifact = null;
+ if (info != null) {
+ artifact = info.getArtifactKey();
+ if (artifact != null) {
+ return artifact;
+ }
+ }
+ if (indexManager instanceof NexusIndexManager) {
+ NexusIndexManager nexusIndexManager = (NexusIndexManager) indexManager;
+ for (IRepository repository : globalRepositories) {
+ NexusIndex nexusIndex = nexusIndexManager.getIndex(repository);
+ if (nexusIndex != null) {
+ try {
+ info = nexusIndex.identify(file);
+ } catch (Throwable t) {
+ // ignore
+ }
+ if (info != null) {
+ artifact = info.getArtifactKey();
+ if (artifact != null) {
+ return artifact;
+ }
+ }
+ }
+ }
+ }
+ //System.err.println(getName() + " could not identify "+file);
+ return artifact;
+ }
+
+ private List<IRepository> initGlobalRepositories() {
+ IRepositoryRegistry repositoryRegistry = MavenPlugin.getRepositoryRegistry();
+ List<IRepository> repositories = repositoryRegistry.
+ getRepositories(IRepositoryRegistry.SCOPE_SETTINGS);
+ return repositories == null? Collections.<IRepository>emptyList():repositories;
+ }
+
+}
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusRepositoryIdentifier.java 2012-08-23
06:59:05 UTC (rev 43185)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -1,148 +0,0 @@
-package org.jboss.tools.maven.sourcelookup.internal.identification;
-
-import static
org.jboss.tools.maven.sourcelookup.identification.IdentificationUtil.getSHA1;
-import static
org.jboss.tools.maven.sourcelookup.identification.IdentificationUtil.getSourcesClassifier;
-
-import java.io.File;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.util.Set;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Unmarshaller;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.m2e.core.embedder.ArtifactKey;
-import org.jboss.tools.maven.sourcelookup.NexusRepository;
-import org.jboss.tools.maven.sourcelookup.SourceLookupActivator;
-import org.jboss.tools.maven.sourcelookup.identification.ArtifactIdentifier;
-import org.sonatype.nexus.rest.model.NexusArtifact;
-import org.sonatype.nexus.rest.model.SearchResponse;
-
-public class NexusRepositoryIdentifier implements ArtifactIdentifier {
-
- private static final String PATH_SEPARATOR = "/";
-
- @Override
- public ArtifactKey identify(File file) throws CoreException {
- return getArtifactFromRemoteNexusRepository(file);
- }
-
- private static ArtifactKey getArtifactFromRemoteNexusRepository(File file) {
- String sha1;
- try {
- sha1 = getSHA1(file);
- } catch (Exception e) {
- return null;
- }
- Set<NexusRepository> nexusRepositories = SourceLookupActivator
- .getNexusRepositories();
- for (NexusRepository repository : nexusRepositories) {
- if (!repository.isEnabled()) {
- continue;
- }
- ArtifactKey key = getArtifactFromRemoteNexusRepository(sha1, repository);
- if (key != null) {
- ArtifactKey sourcesArtifact = new ArtifactKey(
- key.getGroupId(), key.getArtifactId(),
- key.getVersion(),
- getSourcesClassifier(key.getClassifier()));
- ArtifactKey resolvedKey = getSourcesArtifactFromJBossNexusRepository(sourcesArtifact,
repository);
- if (resolvedKey != null) {
- return key;
- }
- }
- }
- return null;
- }
-
- private static ArtifactKey getArtifactFromRemoteNexusRepository(String sha1,
- NexusRepository nexusRepository) {
- if (sha1 == null || nexusRepository == null || nexusRepository.getUrl() == null) {
- return null;
- }
- HttpURLConnection connection = null;
- try {
- String base = nexusRepository.getUrl();
- if (!base.endsWith(PATH_SEPARATOR)) {
- base = base + PATH_SEPARATOR;
- }
- // String url =
- // "https://repository.jboss.org/nexus/service/local/data_index?sha1=";
- String url = base + "service/local/data_index?sha1=";
- url = url + URLEncoder.encode(sha1, "UTF-8");
- JAXBContext context = JAXBContext.newInstance(SearchResponse.class);
- Unmarshaller unmarshaller = context.createUnmarshaller();
- connection = (HttpURLConnection) new URL(url).openConnection();
- connection.connect();
- Object object = unmarshaller.unmarshal(connection.getInputStream());
- if (object instanceof SearchResponse) {
- SearchResponse searchResponse = (SearchResponse) object;
- for (NexusArtifact nexusArtifact : searchResponse.getData()) {
- String groupId = nexusArtifact.getGroupId();
- String artifactId = nexusArtifact.getArtifactId();
- String version = nexusArtifact.getVersion();
- String classifier = nexusArtifact.getClassifier();
- ArtifactKey artifact = new ArtifactKey(groupId, artifactId,
- version, classifier);
- return artifact;
- }
- }
- } catch (Exception e) {
- return null;
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- return null;
- }
-
- private static ArtifactKey getSourcesArtifactFromJBossNexusRepository(ArtifactKey key,
- NexusRepository nexusRepository) {
- if (key == null || nexusRepository == null
- || nexusRepository.getUrl() == null) {
- return null;
- }
- HttpURLConnection connection = null;
- try {
- String base = nexusRepository.getUrl();
- if (!base.endsWith(PATH_SEPARATOR)) {
- base = base + PATH_SEPARATOR;
- }
- // String url =
- //
"https://repository.jboss.org/nexus/service/local/data_index?g=groupId&a=artifactId&v=version&c=classifier";
- String url = base + "service/local/data_index?";
- url= url + "g=" + URLEncoder.encode(key.getGroupId(), "UTF-8") +
"&";
- url= url + "a=" + URLEncoder.encode(key.getArtifactId(), "UTF-8")
+ "&";
- url= url + "v=" + URLEncoder.encode(key.getVersion(), "UTF-8") +
"&";
- url= url + "c=" + URLEncoder.encode(key.getClassifier(),
"UTF-8");
- JAXBContext context = JAXBContext.newInstance(SearchResponse.class);
- Unmarshaller unmarshaller = context.createUnmarshaller();
- connection = (HttpURLConnection) new URL(url).openConnection();
- connection.connect();
- Object object = unmarshaller.unmarshal(connection.getInputStream());
- if (object instanceof SearchResponse) {
- SearchResponse searchResponse = (SearchResponse) object;
- for (NexusArtifact nexusArtifact : searchResponse.getData()) {
- String groupId = nexusArtifact.getGroupId();
- String artifactId = nexusArtifact.getArtifactId();
- String version = nexusArtifact.getVersion();
- String classifier = nexusArtifact.getClassifier();
- ArtifactKey artifact = new ArtifactKey(groupId, artifactId,
- version, classifier);
- return artifact;
- }
- }
- } catch (Exception e) {
- return null;
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- return null;
- }
-
-}
Copied:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java
(from rev 43221,
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/internal/identification/NexusRepositoryIdentifier.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/identification/NexusRepositoryIdentifier.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,122 @@
+/*************************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.core.internal.identification;
+
+import static org.jboss.tools.maven.core.identification.IdentificationUtil.getSHA1;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Set;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.jboss.tools.maven.core.MavenCoreActivator;
+import org.jboss.tools.maven.core.repositories.NexusRepository;
+import org.jboss.tools.maven.core.repositories.RemoteRepositoryManager;
+import org.sonatype.nexus.rest.model.NexusArtifact;
+import org.sonatype.nexus.rest.model.SearchResponse;
+
+public class NexusRepositoryIdentifier extends AbstractArtifactIdentifier {
+
+ public NexusRepositoryIdentifier() {
+ super("Nexus repository identifier");
+ }
+
+ public ArtifactKey identify(File file) throws CoreException {
+ return getArtifactFromRemoteNexusRepository(file);
+ }
+
+ private ArtifactKey getArtifactFromRemoteNexusRepository(File file) {
+ String sha1;
+ try {
+ sha1 = getSHA1(file);
+ } catch (Exception e) {
+ return null;
+ }
+ RemoteRepositoryManager repoManager =
MavenCoreActivator.getDefault().getRepositoryManager();
+ Set<NexusRepository> nexusRepositories = repoManager .getNexusRepositories();
+ for (NexusRepository repository : nexusRepositories) {
+ if (!repository.isEnabled()) {
+ continue;
+ }
+ try {
+ ArtifactKey key =
searchArtifactFromRemoteNexusRepository(repository.getSearchUrl(sha1));
+ if (key != null) {
+ /*
+ Searching for sources here makes no sense here :
+ ex : guice.jar (from seam 2.3) is found in jboss nexus via a SHA1 search but
subsequent search
+ of its sources on this repo returns null => guice.jar can never be identified in
that case!
+ Source resolution / Missing sources should be dealt upstream from here
+
+ String searchSourcesUrl = repository.getSearchUrl(key.getArtifactId(),
+ key.getGroupId(),
+ key.getVersion(),
+ getSourcesClassifier(key.getClassifier()));
+
+ ArtifactKey resolvedKey =
searchArtifactFromRemoteNexusRepository(searchSourcesUrl);
+
+ if (resolvedKey != null) {
+ return key;
+ }
+ */
+ return key;
+ }
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ }
+ //System.err.println(getName()+ "Couldn't find match for SHA1="+sha1);
+ return null;
+ }
+
+ private static ArtifactKey searchArtifactFromRemoteNexusRepository(String searchUrl) {
+ if (searchUrl == null) {
+ return null;
+ }
+ HttpURLConnection connection = null;//TODO use eclipse connections to handle proxies
+ try {
+ JAXBContext context = JAXBContext.newInstance(SearchResponse.class);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ connection = (HttpURLConnection) new URL(searchUrl).openConnection();
+ connection.connect();
+ Object object = unmarshaller.unmarshal(connection.getInputStream());
+ if (object instanceof SearchResponse) {
+ return extractArtifactKey((SearchResponse)object);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return null;
+ }
+
+ private static ArtifactKey extractArtifactKey(SearchResponse searchResponse) {
+ for (NexusArtifact nexusArtifact : searchResponse.getData()) {
+ String groupId = nexusArtifact.getGroupId();
+ String artifactId = nexusArtifact.getArtifactId();
+ String version = nexusArtifact.getVersion();
+ String classifier = nexusArtifact.getClassifier();
+ ArtifactKey artifact = new ArtifactKey(groupId, artifactId,
+ version, classifier);
+ return artifact;
+ }
+ return null;
+ }
+
+}
Copied:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/repositories/NexusRepository.java
(from rev 43221,
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/NexusRepository.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/repositories/NexusRepository.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/repositories/NexusRepository.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,111 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.core.repositories;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+import org.eclipse.core.runtime.Assert;
+
+
+/**
+ *
+ * @author snjeza
+ *
+ */
+public class NexusRepository {
+ private String name;
+ private String url;
+ private boolean enabled;
+
+ private static final String PATH_SEPARATOR = "/";
+
+ public NexusRepository() {
+ super();
+ }
+
+ public NexusRepository(String name, String url, boolean enabled) {
+ super();
+ this.name = name;
+ this.url = url;
+ this.enabled = enabled;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean checked) {
+ this.enabled = checked;
+ }
+
+ @Override
+ public String toString() {
+ return "NexusRepository [name=" + name + ", url=" + url + ",
enabled="
+ + enabled + "]";
+ }
+
+ public String getSearchUrl(String sha1) throws UnsupportedEncodingException {
+ // "https://repository.jboss.org/nexus/service/local/data_index?sha1=";
+ Assert.isNotNull(sha1);
+ StringBuilder searchUrl = getBaseUrl()
+ .append("service/local/data_index?sha1=")
+ .append(URLEncoder.encode(sha1, "UTF-8"));
+ return searchUrl.toString();
+ }
+
+ public String getSearchUrl(String groupId, String artifactId, String version, String
classifier) throws UnsupportedEncodingException {
+ Assert.isNotNull(artifactId);
+ StringBuilder searchUrl = getBaseUrl().append("service/local/data_index?");
+ searchUrl.append("a=").append(URLEncoder.encode(artifactId,
"UTF-8")).append("&");
+ if (groupId != null) {
+ searchUrl.append("g=").append(URLEncoder.encode(groupId,
"UTF-8")).append("&");
+ }
+ if (version != null) {
+ searchUrl.append("v=").append(URLEncoder.encode(version,
"UTF-8")).append("&");
+ }
+ if (classifier != null) {
+ searchUrl.append("c=").append(URLEncoder.encode(classifier,
"UTF-8"));
+ }
+ return searchUrl.toString();
+ }
+
+ private StringBuilder getBaseUrl() {
+ StringBuilder sb = new StringBuilder();
+ String base = getUrl();
+ sb.append(base);
+ if (!base.endsWith(PATH_SEPARATOR)) {
+ sb.append(PATH_SEPARATOR);
+ }
+ return sb;
+ }
+
+
+
+
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/repositories/RemoteRepositoryManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/repositories/RemoteRepositoryManager.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/repositories/RemoteRepositoryManager.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,130 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.core.repositories;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.XMLMemento;
+import org.jboss.tools.maven.core.MavenCoreActivator;
+
+public class RemoteRepositoryManager {
+
+ private static final String NEXUS_REPOSITORIES = "nexusRepositories";
+ private static final String NEXUS_REPOSITORY = "nexusRepository";
+ private static final String NAME = "name";
+ private static final String URL = "url";
+ private static final String ENABLED = "enabled";
+
+ private Set<NexusRepository> nexusRepositories;
+
+ public Set<NexusRepository> getNexusRepositories() {
+ if (nexusRepositories == null) {
+ try {
+ nexusRepositories = loadNexusRepositoriesFromPreferences();
+ } catch (WorkbenchException e) {
+ MavenCoreActivator.log(e);
+ }
+ if (nexusRepositories == null) {
+ getDefaultRepositories();
+ }
+ }
+ return nexusRepositories;
+ }
+
+ public Set<NexusRepository> loadNexusRepositoriesFromPreferences() throws
WorkbenchException {
+ String repositories = getPreferences().get(NEXUS_REPOSITORIES, null);
+ if (repositories == null || repositories.isEmpty()) {
+ return null;
+ }
+ Reader reader = new StringReader(repositories);
+ XMLMemento memento = XMLMemento.createReadRoot(reader);
+ IMemento[] nodes = memento.getChildren(NEXUS_REPOSITORY);
+ for (IMemento node:nodes) {
+ if (nexusRepositories == null) {
+ nexusRepositories = new LinkedHashSet<NexusRepository>();
+ }
+ String name = node.getString(NAME);
+ String url = node.getString(URL);
+ boolean enabled = node.getBoolean(ENABLED);
+ NexusRepository repository = new NexusRepository(name, url, enabled);
+ nexusRepositories.add(repository);
+ }
+ return nexusRepositories;
+ }
+
+ public Set<NexusRepository> getDefaultRepositories() {
+ nexusRepositories = new LinkedHashSet<NexusRepository>();
+ addRepository("JBoss Nexus Repository",
"https://repository.jboss.org/nexus", true);
+ addRepository("Sonatype Nexus Repository",
"http://repository.sonatype.org", false);
+ addRepository("Apache Nexus Repository",
"https://repository.apache.org", false);
+ addRepository("Sonatype OSS Repository", "http://oss.sonatype.org",
false);
+ addRepository("Codehaus Repository", "https://nexus.codehaus.org",
false);
+
addRepository("Java.net Repository", "https://maven.java.net",
false);
+ return nexusRepositories;
+ }
+
+ private void addRepository(String name, String url, boolean enabled) {
+ NexusRepository repository = new NexusRepository(name, url, enabled);
+ nexusRepositories.add(repository);
+ }
+
+ public void setNexusRepositories(Set<NexusRepository> nexusRepositories) {
+ this.nexusRepositories = nexusRepositories;
+ }
+
+ public void saveNexusRepositories() {
+ if (nexusRepositories == null || nexusRepositories.size() == 0) {
+ return;
+ }
+ XMLMemento memento = XMLMemento.createWriteRoot(NEXUS_REPOSITORIES);
+ Writer writer = null;
+ try {
+ for (NexusRepository repository : nexusRepositories) {
+ IMemento repositoryNode = memento.createChild(NEXUS_REPOSITORY);
+ repositoryNode.putString(NAME, repository.getName());
+ repositoryNode.putString(URL, repository.getUrl());
+ repositoryNode.putBoolean(ENABLED, repository.isEnabled());
+ }
+ writer = new StringWriter();
+ memento.save(writer);
+ writer.flush();
+ String repositories = writer.toString();
+ getPreferences().put(NEXUS_REPOSITORIES, repositories);
+ getPreferences().flush();
+ } catch (Exception e) {
+ MavenCoreActivator.log(e);
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ public static IEclipsePreferences getPreferences() {
+ IEclipsePreferences prefs =
InstanceScope.INSTANCE.getNode(MavenCoreActivator.PLUGIN_ID);
+ return prefs;
+ }
+
+}
Modified: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/.classpath
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/.classpath 2012-08-28
01:09:13 UTC (rev 43260)
+++ trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/.classpath 2012-08-28
09:34:41 UTC (rev 43261)
@@ -3,6 +3,5 @@
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
- <classpathentry exported="true" kind="lib"
path="lib/nexus-indexer-lucene-rest-api-client.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Modified:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/META-INF/MANIFEST.MF
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/META-INF/MANIFEST.MF 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/META-INF/MANIFEST.MF 2012-08-28
09:34:41 UTC (rev 43261)
@@ -14,14 +14,12 @@
org.eclipse.m2e.core;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.m2e.maven.runtime;bundle-version="1.0.0";visibility:=reexport,
org.apache.commons.codec;bundle-version="1.3.0",
- org.eclipse.ui;bundle-version="3.7.0"
+ org.eclipse.ui;bundle-version="3.7.0",
+ org.jboss.tools.maven.core;bundle-version="1.4.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: %BundleVendor
Bundle-Localization: plugin
Export-Package: org.jboss.tools.maven.sourcelookup,
- org.jboss.tools.maven.sourcelookup.containers,
- org.jboss.tools.maven.sourcelookup.identification,
- org.jboss.tools.maven.sourcelookup.internal.identification
-Bundle-ClassPath: .,
- lib/nexus-indexer-lucene-rest-api-client.jar
+ org.jboss.tools.maven.sourcelookup.containers
+Bundle-ClassPath: .
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/NexusRepository.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/NexusRepository.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/NexusRepository.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -1,111 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2008-2012 Red Hat, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- *
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * JBoss by Red Hat - Initial implementation.
- ************************************************************************************/
-package org.jboss.tools.maven.sourcelookup;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
-import org.eclipse.core.runtime.Assert;
-
-
-/**
- *
- * @author snjeza
- *
- */
-public class NexusRepository {
- private String name;
- private String url;
- private boolean enabled;
-
- private static final String PATH_SEPARATOR = "/";
-
- public NexusRepository() {
- super();
- }
-
- public NexusRepository(String name, String url, boolean enabled) {
- super();
- this.name = name;
- this.url = url;
- this.enabled = enabled;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean checked) {
- this.enabled = checked;
- }
-
- @Override
- public String toString() {
- return "NexusRepository [name=" + name + ", url=" + url + ",
enabled="
- + enabled + "]";
- }
-
- public String getSearchUrl(String sha1) throws UnsupportedEncodingException {
- // "https://repository.jboss.org/nexus/service/local/data_index?sha1=";
- Assert.isNotNull(sha1);
- StringBuilder searchUrl = getBaseUrl()
- .append("service/local/data_index?sha1=")
- .append(URLEncoder.encode(sha1, "UTF-8"));
- return searchUrl.toString();
- }
-
- public String getSearchUrl(String groupId, String artifactId, String version, String
classifier) throws UnsupportedEncodingException {
- Assert.isNotNull(artifactId);
- StringBuilder searchUrl = getBaseUrl().append("service/local/data_index?");
- searchUrl.append("a=").append(URLEncoder.encode(artifactId,
"UTF-8")).append("&");
- if (groupId != null) {
- searchUrl.append("g=").append(URLEncoder.encode(groupId,
"UTF-8")).append("&");
- }
- if (version != null) {
- searchUrl.append("v=").append(URLEncoder.encode(version,
"UTF-8")).append("&");
- }
- if (classifier != null) {
- searchUrl.append("c=").append(URLEncoder.encode(classifier,
"UTF-8"));
- }
- return searchUrl.toString();
- }
-
- private StringBuilder getBaseUrl() {
- StringBuilder sb = new StringBuilder();
- String base = getUrl();
- sb.append(base);
- if (!base.endsWith(PATH_SEPARATOR)) {
- sb.append(PATH_SEPARATOR);
- }
- return sb;
- }
-
-
-
-
-
-}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/SourceLookupActivator.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/SourceLookupActivator.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/SourceLookupActivator.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -10,14 +10,6 @@
************************************************************************************/
package org.jboss.tools.maven.sourcelookup;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
import org.eclipse.core.internal.runtime.InternalPlatform;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
@@ -28,9 +20,6 @@
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.WorkbenchException;
-import org.eclipse.ui.XMLMemento;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -50,14 +39,7 @@
public static final String JBOSS_LAUNCH_SOURCE_PATH_COMPUTER_ID =
"org.jboss.tools.maven.sourcelookup.SourcePathComputer"; //$NON-NLS-1$
public static final String AUTO_ADD_JBOSS_SOURCE_CONTAINER =
"autoAddJBossSourceContainer";
public static final boolean AUTO_ADD_JBOSS_SOURCE_CONTAINER_DEFAULT = false;
- private static final String NEXUS_REPOSITORIES = "nexusRepositories";
- private static final String NEXUS_REPOSITORY = "nexusRepository";
- private static final String NAME = "name";
- private static final String URL = "url";
- private static final String ENABLED = "enabled";
- private static Set<NexusRepository> nexusRepositories;
-
// The shared instance
private static SourceLookupActivator plugin;
@@ -148,90 +130,4 @@
.equals(configuration.getType().getIdentifier());
}
- public static Set<NexusRepository> getNexusRepositories() {
- if (nexusRepositories == null) {
- try {
- nexusRepositories = loadNexusRepositoriesFromPreferences();
- } catch (WorkbenchException e) {
- log(e);
- }
- if (nexusRepositories == null) {
- getDefaultRepositories();
- }
- }
- return nexusRepositories;
- }
-
- public static Set<NexusRepository> loadNexusRepositoriesFromPreferences() throws
WorkbenchException {
- String repositories = getPreferences().get(NEXUS_REPOSITORIES, null);
- if (repositories == null || repositories.isEmpty()) {
- return null;
- }
- Reader reader = new StringReader(repositories);
- XMLMemento memento = XMLMemento.createReadRoot(reader);
- IMemento[] nodes = memento.getChildren(NEXUS_REPOSITORY);
- for (IMemento node:nodes) {
- if (nexusRepositories == null) {
- nexusRepositories = new LinkedHashSet<NexusRepository>();
- }
- String name = node.getString(NAME);
- String url = node.getString(URL);
- boolean enabled = node.getBoolean(ENABLED);
- NexusRepository repository = new NexusRepository(name, url, enabled);
- nexusRepositories.add(repository);
- }
- return nexusRepositories;
- }
-
- public static Set<NexusRepository> getDefaultRepositories() {
- nexusRepositories = new LinkedHashSet<NexusRepository>();
- addRepository("JBoss Nexus Repository",
"https://repository.jboss.org/nexus", true);
- addRepository("Sonatype Nexus Repository",
"http://repository.sonatype.org", false);
- addRepository("Apache Nexus Repository",
"https://repository.apache.org", false);
- addRepository("Sonatype OSS Repository", "http://oss.sonatype.org",
false);
- addRepository("Codehaus Repository", "https://nexus.codehaus.org",
false);
-
addRepository("Java.net Repository", "https://maven.java.net",
false);
- return nexusRepositories;
- }
-
- private static void addRepository(String name, String url, boolean enabled) {
- NexusRepository repository = new NexusRepository(name, url, enabled);
- nexusRepositories.add(repository);
- }
-
- public static void setNexusRepositories(Set<NexusRepository> nexusRepositories) {
- SourceLookupActivator.nexusRepositories = nexusRepositories;
- }
-
- public static void saveNexusRepositories() {
- if (nexusRepositories == null || nexusRepositories.size() == 0) {
- return;
- }
- XMLMemento memento = XMLMemento.createWriteRoot(NEXUS_REPOSITORIES);
- Writer writer = null;
- try {
- for (NexusRepository repository:nexusRepositories) {
- IMemento repositoryNode = memento.createChild(NEXUS_REPOSITORY);
- repositoryNode.putString(NAME, repository.getName());
- repositoryNode.putString(URL, repository.getUrl());
- repositoryNode.putBoolean(ENABLED, repository.isEnabled());
- }
- writer = new StringWriter();
- memento.save(writer);
- writer.flush();
- String repositories = writer.toString();
- getPreferences().put(NEXUS_REPOSITORIES, repositories);
- getPreferences().flush();
- } catch (Exception e) {
- log(e);
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- }
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/containers/JBossSourceContainer.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/containers/JBossSourceContainer.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.core/src/org/jboss/tools/maven/sourcelookup/containers/JBossSourceContainer.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -10,8 +10,6 @@
************************************************************************************/
package org.jboss.tools.maven.sourcelookup.containers;
-import static
org.jboss.tools.maven.sourcelookup.identification.IdentificationUtil.getSourcesClassifier;
-
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -49,9 +47,10 @@
import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.tools.maven.core.identification.IFileIdentificationManager;
+import org.jboss.tools.maven.core.identification.IdentificationUtil;
+import org.jboss.tools.maven.core.internal.identification.FileIdentificationManager;
import org.jboss.tools.maven.sourcelookup.SourceLookupActivator;
-import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
-import
org.jboss.tools.maven.sourcelookup.internal.identification.FileIdentificationManager;
/**
*
@@ -302,7 +301,7 @@
final ArtifactKey sourcesArtifact = new ArtifactKey(
artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(),
- getSourcesClassifier(artifact.getClassifier()));
+ IdentificationUtil.getSourcesClassifier(artifact.getClassifier()));
resolvedFile = null;
Job job = new Job("Downloading sources for " + file.getName()) {
@@ -348,7 +347,7 @@
public static IPath getSourcePath(ArtifactKey a) {
File file = getAttachedArtifactFile(a,
- getSourcesClassifier(a.getClassifier()));
+ IdentificationUtil.getSourcesClassifier(a.getClassifier()));
if (file != null) {
return Path.fromOSString(file.getAbsolutePath());
Modified: trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/META-INF/MANIFEST.MF 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/META-INF/MANIFEST.MF 2012-08-28
09:34:41 UTC (rev 43261)
@@ -7,6 +7,7 @@
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.jboss.tools.maven.sourcelookup.core;bundle-version="1.0.0",
+ org.jboss.tools.maven.core;bundle-version="1.4.0",
org.eclipse.debug.ui;bundle-version="3.7.0",
org.eclipse.jdt.ui;bundle-version="3.7.1"
Bundle-ActivationPolicy: lazy
Modified:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/actions/AttachSourcesActionDelegate.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/actions/AttachSourcesActionDelegate.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/actions/AttachSourcesActionDelegate.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -37,10 +37,10 @@
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
+import org.jboss.tools.maven.core.identification.IFileIdentificationManager;
+import org.jboss.tools.maven.core.internal.identification.FileIdentificationManager;
import org.jboss.tools.maven.sourcelookup.SourceLookupActivator;
import org.jboss.tools.maven.sourcelookup.containers.JBossSourceContainer;
-import org.jboss.tools.maven.sourcelookup.identification.IFileIdentificationManager;
-import
org.jboss.tools.maven.sourcelookup.internal.identification.FileIdentificationManager;
import org.jboss.tools.maven.sourcelookup.ui.SourceLookupUIActivator;
/**
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/browsers/EditNexusRepositoryDialog.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/browsers/EditNexusRepositoryDialog.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/browsers/EditNexusRepositoryDialog.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -1,122 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2010-2011 Red Hat, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- *
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * JBoss by Red Hat - Initial implementation.
- ************************************************************************************/
-package org.jboss.tools.maven.sourcelookup.ui.browsers;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.jboss.tools.maven.sourcelookup.NexusRepository;
-
-/**
- * @author snjeza
- *
- */
-public class EditNexusRepositoryDialog extends Dialog {
-
- private NexusRepository nexusRepository;
- private String title;
-
- public EditNexusRepositoryDialog(Shell parentShell, NexusRepository repository) {
- super(parentShell);
- setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER
- | SWT.RESIZE | getDefaultOrientation());
- this.nexusRepository = repository;
- if (this.nexusRepository == null) {
- this.nexusRepository = new NexusRepository("", "", true);
- this.title = "New Repository";
- } else {
- this.title = "Edit Repository";
- }
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- getShell().setText(title);
- Composite area = (Composite) super.createDialogArea(parent);
- Composite contents = new Composite(area, SWT.NONE);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 100;
- gd.widthHint = 400;
- contents.setLayoutData(gd);
- contents.setLayout(new GridLayout(2, false));
- applyDialogFont(contents);
- initializeDialogUnits(area);
-
- Label nameLabel = new Label(contents, SWT.NONE);
- nameLabel.setText("Name:");
-
- final Text nameText = new Text(contents, SWT.BORDER);
- gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- nameText.setLayoutData(gd);
- nameText.setText(nexusRepository.getName());
-
- nameText.addModifyListener(new ModifyListener() {
-
- @Override
- public void modifyText(ModifyEvent e) {
- nexusRepository.setName(nameText.getText());
- }
- });
-
- Label urlLabel = new Label(contents, SWT.NONE);
- urlLabel.setText("URL:");
-
- final Text urlText = new Text(contents, SWT.BORDER);
- gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- urlText.setLayoutData(gd);
- urlText.setText(nexusRepository.getUrl());
-
- urlText.addModifyListener(new ModifyListener() {
-
- @Override
- public void modifyText(ModifyEvent e) {
- nexusRepository.setUrl(urlText.getText());
- }
- });
-
- final Button enabledButton = new Button(contents, SWT.CHECK);
- gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- gd.horizontalSpan = 2;
- enabledButton.setLayoutData(gd);
- enabledButton.setText("Enabled");
- enabledButton.setSelection(nexusRepository.isEnabled());
- enabledButton.addSelectionListener(new SelectionListener() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- nexusRepository.setEnabled(enabledButton.getSelection());
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
- });
-
- return area;
- }
-
- public NexusRepository getNexusRepository() {
- return nexusRepository;
- }
-
-}
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/AutoResizeTableLayout.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/AutoResizeTableLayout.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/AutoResizeTableLayout.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -1,129 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2010-2011 Red Hat, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- *
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * JBoss by Red Hat - Initial implementation.
- ************************************************************************************/
-package org.jboss.tools.maven.sourcelookup.ui.preferences;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.viewers.ColumnLayoutData;
-import org.eclipse.jface.viewers.ColumnPixelData;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.TableLayout;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-
-public class AutoResizeTableLayout extends TableLayout implements
- ControlListener {
-
- private final Table table;
- private List<ColumnLayoutData> columns = new
ArrayList<ColumnLayoutData>();
- private boolean autosizing = false;
-
- public AutoResizeTableLayout(Table table) {
- this.table = table;
- table.addControlListener(this);
- }
-
- public void addColumnData(ColumnLayoutData data) {
- columns.add(data);
- super.addColumnData(data);
- }
-
- public void controlMoved(ControlEvent e) {
- }
-
- public void controlResized(ControlEvent e) {
- if (autosizing) {
- return;
- }
- autosizing = true;
- try {
- autoSizeColumns();
- } finally {
- autosizing = false;
- }
- }
-
- private void autoSizeColumns() {
- int width = table.getClientArea().width;
- if (width <= 1) {
- return;
- }
-
- TableColumn[] tableColumns = table.getColumns();
- int size =
- Math.min(columns.size(), tableColumns.length);
- int[] widths = new int[size];
- int fixedWidth = 0;
- int numberOfWeightColumns = 0;
- int totalWeight = 0;
-
- // First calc space occupied by fixed columns.
- for (int i = 0; i < size; i++) {
- ColumnLayoutData col = (ColumnLayoutData)columns.get(i);
- if (col instanceof ColumnPixelData) {
- int pixels = ((ColumnPixelData)col).width;
- widths[i] = pixels;
- fixedWidth += pixels;
- } else if (col instanceof ColumnWeightData) {
- ColumnWeightData cw = (ColumnWeightData)col;
- numberOfWeightColumns++;
- int weight = cw.weight;
- totalWeight += weight;
- } else {
- throw new IllegalStateException("Unknown column layout data");
- }
- }
-
- // Do we have columns that have a weight?
- if (numberOfWeightColumns > 0) {
- // Now, distribute the rest
- // to the columns with weight.
- int rest = width - fixedWidth;
- int totalDistributed = 0;
- for (int i = 0; i < size; i++) {
- ColumnLayoutData col = (ColumnLayoutData)columns.get(i);
- if (col instanceof ColumnWeightData) {
- ColumnWeightData cw = (ColumnWeightData)col;
- int weight = cw.weight;
- int pixels = totalWeight == 0 ? 0 : weight * rest / totalWeight;
- totalDistributed += pixels;
- widths[i] = pixels;
- }
- }
-
- // Distribute any remaining pixels
- // to columns with weight.
- int diff = rest - totalDistributed;
- for (int i = 0; diff > 0; i++) {
- if (i == size) {
- i = 0;
- }
- ColumnLayoutData col = (ColumnLayoutData)columns.get(i);
- if (col instanceof ColumnWeightData) {
- ++widths[i];
- --diff;
- }
- }
- }
-
- for (int i = 0; i < size; i++) {
- if (tableColumns[i].getWidth() != widths[i]) {
- tableColumns[i].setWidth(widths[i]);
- }
-
- }
-
- }
-
-}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/SourceLookupPreferencePage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/SourceLookupPreferencePage.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/SourceLookupPreferencePage.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -10,44 +10,17 @@
************************************************************************************/
package org.jboss.tools.maven.sourcelookup.ui.preferences;
-import java.util.Iterator;
-import java.util.Set;
-
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.ColumnLayoutData;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableLayout;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.jboss.tools.maven.sourcelookup.NexusRepository;
import org.jboss.tools.maven.sourcelookup.SourceLookupActivator;
-import org.jboss.tools.maven.sourcelookup.ui.browsers.EditNexusRepositoryDialog;
/**
*
@@ -58,8 +31,6 @@
IWorkbenchPreferencePage {
private Button autoAddButton;
- private CheckboxTableViewer tableViewer;
- private Set<NexusRepository> nexusRepositories;
@Override
public void init(IWorkbench workbench) {
@@ -67,6 +38,7 @@
@Override
protected Control createContents(Composite parent) {
+
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NONE);
@@ -82,62 +54,6 @@
autoAddButton
.setText("Automatically add the JBoss Maven source container to all JBoss AS
launch configurations");
- // Nexus Repositories
- Group group = new Group(composite, SWT.NONE);
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- group.setLayoutData(gd);
- layout = new GridLayout(2, false);
- group.setLayout(layout);
- group.setText("Nexus Index Repositories");
- tableViewer = CheckboxTableViewer
- .newCheckList(group, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE);
- Table table = tableViewer.getTable();
- gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 300;
- table.setLayoutData(gd);
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
-
- String[] columnNames = new String[] { "Name", "URL" };
- int[] columnWidths = new int[] { 200, 200 };
-
- for (int i = 0; i < columnNames.length; i++) {
- TableColumn tc = new TableColumn(table, SWT.LEFT);
- tc.setText(columnNames[i]);
- tc.setWidth(columnWidths[i]);
- }
-
- ColumnLayoutData[] layouts = {
- new ColumnWeightData(200,200),
- new ColumnWeightData(200,200)
- };
-
- TableLayout tableLayout = new AutoResizeTableLayout(table);
- for (int i = 0; i < layouts.length; i++) {
- tableLayout.addColumnData(layouts[i]);
- }
-
- nexusRepositories = SourceLookupActivator
- .getNexusRepositories();
- tableViewer.setLabelProvider(new NexusRepositoryLabelProvider());
- tableViewer.setContentProvider(new NexusRepositoryContentProvider(
- nexusRepositories));
-
- tableViewer.setInput(nexusRepositories);
- for (NexusRepository nexusRepository : nexusRepositories) {
- tableViewer.setChecked(nexusRepository,
- nexusRepository.isEnabled());
- }
- tableViewer.addCheckStateListener(new ICheckStateListener() {
-
- public void checkStateChanged(CheckStateChangedEvent event) {
- NexusRepository repository = (NexusRepository) event
- .getElement();
- repository.setEnabled(!repository.isEnabled());
- }
- });
-
- createButtons(group, tableViewer);
return composite;
}
@@ -146,226 +62,6 @@
super.dispose();
}
- private void createButtons(Composite parent, final TableViewer viewer) {
- Composite buttonComposite = new Composite(parent, SWT.NONE);
- buttonComposite.setLayout(new GridLayout(1,false));
- buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
-
- Button addButton = new Button(buttonComposite, SWT.PUSH);
- addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- addButton.setText("Add...");
- addButton.addSelectionListener(new SelectionListener(){
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
-
- public void widgetSelected(SelectionEvent e) {
- EditNexusRepositoryDialog dialog = new EditNexusRepositoryDialog(getShell(), null);
- int ok = dialog.open();
- if (ok == Window.OK) {
- NexusRepository repository = dialog.getNexusRepository();
- nexusRepositories.add(repository);
- viewer.refresh();
- tableViewer.setChecked(repository,
- repository.isEnabled());
- }
- viewer.refresh();
- }
-
- });
-
- final Button editButton = new Button(buttonComposite, SWT.PUSH);
- editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- editButton.setText("Edit...");
- editButton.setEnabled(false);
-
- editButton.addSelectionListener(new SelectionListener(){
-
- public void widgetSelected(SelectionEvent e) {
- ISelection sel = viewer.getSelection();
- if (sel instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection) sel;
- Object object = selection.getFirstElement();
- if (object instanceof NexusRepository) {
- NexusRepository repository = (NexusRepository) object;
- NexusRepository edit = new NexusRepository(repository.getName(),
repository.getUrl(), repository.isEnabled());
- EditNexusRepositoryDialog dialog = new EditNexusRepositoryDialog(getShell(),
edit);
- int ok = dialog.open();
- if (ok == Window.OK) {
- repository.setName(edit.getName());
- repository.setUrl(edit.getUrl());
- repository.setEnabled(edit.isEnabled());
- viewer.refresh();
- tableViewer.setChecked(repository,
- repository.isEnabled());
- }
- }
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
- });
-
- final Button removeButton = new Button(buttonComposite, SWT.PUSH);
- removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- removeButton.setText("Remove");
- removeButton.setEnabled(false);
-
- removeButton.addSelectionListener(new SelectionListener(){
-
- public void widgetSelected(SelectionEvent e) {
- ISelection sel = viewer.getSelection();
- if (sel instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection) sel;
- Object object = selection.getFirstElement();
- if (object instanceof NexusRepository) {
- nexusRepositories.remove(object);
- viewer.refresh();
- }
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
- });
-
- final Button upButton = new Button(buttonComposite, SWT.PUSH);
- upButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- upButton.setText("Up");
- upButton.setEnabled(false);
-
- final Button downButton = new Button(buttonComposite, SWT.PUSH);
- downButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- downButton.setText("Down");
- downButton.setEnabled(false);
-
- upButton.addSelectionListener(new SelectionListener(){
-
- public void widgetSelected(SelectionEvent e) {
- ISelection sel = viewer.getSelection();
- if (sel instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection) sel;
- Object object = selection.getFirstElement();
- if (object instanceof NexusRepository) {
- NexusRepository selected = (NexusRepository) object;
- NexusRepository[] reps = nexusRepositories.toArray(new NexusRepository[0]);
- int selectedIndex = -1;
- for (int i = 0; i < reps.length; i++) {
- NexusRepository rep = reps[i];
- if (selected.equals(rep)) {
- selectedIndex = i;
- break;
- }
- }
- if (selectedIndex > 0) {
- NexusRepository temp = reps[selectedIndex-1];
- reps[selectedIndex - 1] = selected;
- reps[selectedIndex] = temp;
- nexusRepositories.clear();
- for (NexusRepository repository:reps) {
- nexusRepositories.add(repository);
- }
- viewer.refresh();
- int newIndex = selectedIndex - 1;
- downButton.setEnabled( newIndex < (reps.length - 1));
- upButton.setEnabled(newIndex > 0);
-
- }
- }
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
- });
-
- downButton.addSelectionListener(new SelectionListener(){
-
- public void widgetSelected(SelectionEvent e) {
- ISelection sel = viewer.getSelection();
- if (sel instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection) sel;
- Object object = selection.getFirstElement();
- if (object instanceof NexusRepository) {
- NexusRepository selected = (NexusRepository) object;
- NexusRepository[] reps = nexusRepositories.toArray(new NexusRepository[0]);
- int selectedIndex = -1;
- for (int i = 0; i < reps.length; i++) {
- NexusRepository rep = reps[i];
- if (selected.equals(rep)) {
- selectedIndex = i;
- break;
- }
- }
- if (selectedIndex >= 0 && selectedIndex < reps.length) {
- NexusRepository temp = reps[selectedIndex + 1];
- reps[selectedIndex + 1] = selected;
- reps[selectedIndex] = temp;
- nexusRepositories.clear();
- for (NexusRepository repository:reps) {
- nexusRepositories.add(repository);
- }
- viewer.refresh();
- int newIndex = selectedIndex + 1;
- downButton.setEnabled( newIndex < (reps.length - 1));
- upButton.setEnabled(newIndex > 0);
- }
- }
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
- });
-
- viewer.addSelectionChangedListener(new ISelectionChangedListener() {
-
- public void selectionChanged(SelectionChangedEvent event) {
- ISelection sel = viewer.getSelection();
- if (sel instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection) sel;
- Object object = selection.getFirstElement();
- editButton.setEnabled(object instanceof NexusRepository);
- removeButton.setEnabled(object instanceof NexusRepository);
- upButton.setEnabled(false);
- downButton.setEnabled(false);
- if (object instanceof NexusRepository && nexusRepositories.size() > 1) {
- NexusRepository repository = (NexusRepository) object;
- Iterator<NexusRepository> iterator = nexusRepositories.iterator();
- NexusRepository first = null;
- if (iterator.hasNext()) {
- first = iterator.next();
- }
- NexusRepository last = null;
- while (iterator.hasNext()) {
- last = iterator.next();
- }
- if (repository.equals(last)) {
- upButton.setEnabled(true);
- } else if (repository.equals(first)) {
- downButton.setEnabled(true);
- } else {
- upButton.setEnabled(true);
- downButton.setEnabled(true);
- }
-
- }
- } else {
- editButton.setEnabled(false);
- removeButton.setEnabled(false);
- upButton.setEnabled(false);
- downButton.setEnabled(false);
- }
- }
- });
- }
-
@Override
protected void performApply() {
IEclipsePreferences preferences = SourceLookupActivator.getDefault()
@@ -373,14 +69,7 @@
preferences.putBoolean(
SourceLookupActivator.AUTO_ADD_JBOSS_SOURCE_CONTAINER,
autoAddButton.getSelection());
- SourceLookupActivator.setNexusRepositories(nexusRepositories);
- SourceLookupActivator.saveNexusRepositories();
SourceLookupActivator.getDefault().savePreferences();
- tableViewer.setInput(nexusRepositories);
- for (NexusRepository nexusRepository : nexusRepositories) {
- tableViewer.setChecked(nexusRepository,
- nexusRepository.isEnabled());
- }
}
@Override
@@ -392,15 +81,6 @@
preferences.putBoolean(
SourceLookupActivator.AUTO_ADD_JBOSS_SOURCE_CONTAINER,
SourceLookupActivator.AUTO_ADD_JBOSS_SOURCE_CONTAINER_DEFAULT);
- SourceLookupActivator.setNexusRepositories(null);
- nexusRepositories = SourceLookupActivator.getDefaultRepositories();
- SourceLookupActivator.saveNexusRepositories();
- SourceLookupActivator.getDefault().savePreferences();
- tableViewer.setInput(nexusRepositories);
- for (NexusRepository nexusRepository : nexusRepositories) {
- tableViewer.setChecked(nexusRepository,
- nexusRepository.isEnabled());
- }
super.performDefaults();
}
@@ -409,53 +89,4 @@
performApply();
return super.performOk();
}
-
- private class NexusRepositoryLabelProvider extends LabelProvider implements
- ITableLabelProvider {
-
- public Image getColumnImage(Object element, int columnIndex) {
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- if (element instanceof NexusRepository) {
- NexusRepository nr = (NexusRepository) element;
- if (columnIndex == 0) {
- return nr.getName();
- }
- if (columnIndex == 1) {
- return nr.getUrl();
- }
- }
- return null;
- }
- }
-
- private class NexusRepositoryContentProvider implements
- IStructuredContentProvider {
-
- private Set<NexusRepository> repositories;
-
- public NexusRepositoryContentProvider(Set<NexusRepository> repositories) {
- this.repositories = repositories;
- }
-
- public Object[] getElements(Object inputElement) {
- return repositories.toArray();
- }
-
- public void dispose() {
-
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- repositories = (Set<NexusRepository>) newInput;
- }
- }
-
- @Override
- public boolean performCancel() {
- SourceLookupActivator.setNexusRepositories(null);
- return super.performCancel();
- }
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/.settings/org.eclipse.jdt.core.prefs
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/.settings/org.eclipse.jdt.core.prefs 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/.settings/org.eclipse.jdt.core.prefs 2012-08-28
09:34:41 UTC (rev 43261)
@@ -1,9 +1,8 @@
-#Thu May 28 22:27:10 CEST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.6
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/.settings/org.eclipse.m2e.core.prefs
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/.settings/org.eclipse.m2e.core.prefs 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/.settings/org.eclipse.m2e.core.prefs 2012-08-28
09:34:41 UTC (rev 43261)
@@ -1,5 +1,4 @@
-#Tue Jun 28 11:43:06 CEST 2011
-activeProfiles=
-eclipse.preferences.version=1
-resolveWorkspaceProjects=true
-version=1
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
Modified: trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2012-08-28 01:09:13 UTC (rev
43260)
+++ trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2012-08-28 09:34:41 UTC (rev
43261)
@@ -159,4 +159,15 @@
name="%Configure_Maven_Repositories">
</wizard>
</extension>
+
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.jboss.tools.common.model.ui.MainPreferencePage"
+
class="org.jboss.tools.maven.ui.preferences.RemoteRepositoriesPreferencePage"
+
id="org.jboss.tools.maven.ui.preferences.RemoteRepositoriesPreferencePage"
+ name="Remote Repositories"/>
+ </extension>
+
+
</plugin>
Copied:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/repositories/EditNexusRepositoryDialog.java
(from rev 43185,
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/browsers/EditNexusRepositoryDialog.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/repositories/EditNexusRepositoryDialog.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/repositories/EditNexusRepositoryDialog.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,123 @@
+/*************************************************************************************
+ * Copyright (c) 2010-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.ui.internal.repositories;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.maven.core.repositories.NexusRepository;
+
+/**
+ * @author snjeza
+ *
+ */
+public class EditNexusRepositoryDialog extends Dialog {
+
+ private NexusRepository nexusRepository;
+ private String title;
+
+ public EditNexusRepositoryDialog(Shell parentShell,
+ NexusRepository repository) {
+ super(parentShell);
+ setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER | SWT.RESIZE
+ | getDefaultOrientation());
+ this.nexusRepository = repository;
+ if (this.nexusRepository == null) {
+ this.nexusRepository = new NexusRepository("", "", true);
+ this.title = "New Repository";
+ } else {
+ this.title = "Edit Repository";
+ }
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ getShell().setText(title);
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite contents = new Composite(area, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 100;
+ gd.widthHint = 400;
+ contents.setLayoutData(gd);
+ contents.setLayout(new GridLayout(2, false));
+ applyDialogFont(contents);
+ initializeDialogUnits(area);
+
+ Label nameLabel = new Label(contents, SWT.NONE);
+ nameLabel.setText("Name:");
+
+ final Text nameText = new Text(contents, SWT.BORDER);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ nameText.setLayoutData(gd);
+ nameText.setText(nexusRepository.getName());
+
+ nameText.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ nexusRepository.setName(nameText.getText());
+ }
+ });
+
+ Label urlLabel = new Label(contents, SWT.NONE);
+ urlLabel.setText("URL:");
+
+ final Text urlText = new Text(contents, SWT.BORDER);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ urlText.setLayoutData(gd);
+ urlText.setText(nexusRepository.getUrl());
+
+ urlText.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ nexusRepository.setUrl(urlText.getText());
+ }
+ });
+
+ final Button enabledButton = new Button(contents, SWT.CHECK);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gd.horizontalSpan = 2;
+ enabledButton.setLayoutData(gd);
+ enabledButton.setText("Enabled");
+ enabledButton.setSelection(nexusRepository.isEnabled());
+ enabledButton.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ nexusRepository.setEnabled(enabledButton.getSelection());
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ return area;
+ }
+
+ public NexusRepository getNexusRepository() {
+ return nexusRepository;
+ }
+
+}
Copied:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/preferences/AutoResizeTableLayout.java
(from rev 43185,
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/AutoResizeTableLayout.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/preferences/AutoResizeTableLayout.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/preferences/AutoResizeTableLayout.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,129 @@
+/*************************************************************************************
+ * Copyright (c) 2010-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.ui.preferences;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ColumnLayoutData;
+import org.eclipse.jface.viewers.ColumnPixelData;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class AutoResizeTableLayout extends TableLayout implements
+ ControlListener {
+
+ private final Table table;
+ private List<ColumnLayoutData> columns = new
ArrayList<ColumnLayoutData>();
+ private boolean autosizing = false;
+
+ public AutoResizeTableLayout(Table table) {
+ this.table = table;
+ table.addControlListener(this);
+ }
+
+ public void addColumnData(ColumnLayoutData data) {
+ columns.add(data);
+ super.addColumnData(data);
+ }
+
+ public void controlMoved(ControlEvent e) {
+ }
+
+ public void controlResized(ControlEvent e) {
+ if (autosizing) {
+ return;
+ }
+ autosizing = true;
+ try {
+ autoSizeColumns();
+ } finally {
+ autosizing = false;
+ }
+ }
+
+ private void autoSizeColumns() {
+ int width = table.getClientArea().width;
+ if (width <= 1) {
+ return;
+ }
+
+ TableColumn[] tableColumns = table.getColumns();
+ int size =
+ Math.min(columns.size(), tableColumns.length);
+ int[] widths = new int[size];
+ int fixedWidth = 0;
+ int numberOfWeightColumns = 0;
+ int totalWeight = 0;
+
+ // First calc space occupied by fixed columns.
+ for (int i = 0; i < size; i++) {
+ ColumnLayoutData col = (ColumnLayoutData)columns.get(i);
+ if (col instanceof ColumnPixelData) {
+ int pixels = ((ColumnPixelData)col).width;
+ widths[i] = pixels;
+ fixedWidth += pixels;
+ } else if (col instanceof ColumnWeightData) {
+ ColumnWeightData cw = (ColumnWeightData)col;
+ numberOfWeightColumns++;
+ int weight = cw.weight;
+ totalWeight += weight;
+ } else {
+ throw new IllegalStateException("Unknown column layout data");
+ }
+ }
+
+ // Do we have columns that have a weight?
+ if (numberOfWeightColumns > 0) {
+ // Now, distribute the rest
+ // to the columns with weight.
+ int rest = width - fixedWidth;
+ int totalDistributed = 0;
+ for (int i = 0; i < size; i++) {
+ ColumnLayoutData col = (ColumnLayoutData)columns.get(i);
+ if (col instanceof ColumnWeightData) {
+ ColumnWeightData cw = (ColumnWeightData)col;
+ int weight = cw.weight;
+ int pixels = totalWeight == 0 ? 0 : weight * rest / totalWeight;
+ totalDistributed += pixels;
+ widths[i] = pixels;
+ }
+ }
+
+ // Distribute any remaining pixels
+ // to columns with weight.
+ int diff = rest - totalDistributed;
+ for (int i = 0; diff > 0; i++) {
+ if (i == size) {
+ i = 0;
+ }
+ ColumnLayoutData col = (ColumnLayoutData)columns.get(i);
+ if (col instanceof ColumnWeightData) {
+ ++widths[i];
+ --diff;
+ }
+ }
+ }
+
+ for (int i = 0; i < size; i++) {
+ if (tableColumns[i].getWidth() != widths[i]) {
+ tableColumns[i].setWidth(widths[i]);
+ }
+
+ }
+
+ }
+
+}
Copied:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/preferences/RemoteRepositoriesPreferencePage.java
(from rev 43185,
trunk/maven/plugins/org.jboss.tools.maven.sourcelookup.ui/src/org/jboss/tools/maven/sourcelookup/ui/preferences/SourceLookupPreferencePage.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/preferences/RemoteRepositoriesPreferencePage.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/preferences/RemoteRepositoriesPreferencePage.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -0,0 +1,451 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.ui.preferences;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnLayoutData;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.jboss.tools.maven.core.MavenCoreActivator;
+import org.jboss.tools.maven.core.repositories.NexusRepository;
+import org.jboss.tools.maven.core.repositories.RemoteRepositoryManager;
+import org.jboss.tools.maven.ui.internal.repositories.EditNexusRepositoryDialog;
+
+/**
+ *
+ * @author snjeza
+ *
+ */
+public class RemoteRepositoriesPreferencePage extends PreferencePage implements
+ IWorkbenchPreferencePage {
+
+ private CheckboxTableViewer tableViewer;
+ private Set<NexusRepository> nexusRepositories;
+
+ private RemoteRepositoryManager remoteRepositoryManager;
+
+ @Override
+ public void init(IWorkbench workbench) {
+ remoteRepositoryManager = MavenCoreActivator.getDefault().getRepositoryManager();
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setLayout(layout);
+
+ Label label = new Label(composite, SWT.FILL);
+ label.setText("Remote repositories used for dependency identification (only Nexus
repositories are supported).");
+
+ // Nexus Repositories
+ Group group = new Group(composite, SWT.NONE);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ group.setLayoutData(gd);
+ layout = new GridLayout(2, false);
+ group.setLayout(layout);
+ group.setText("Remote Repositories");
+ tableViewer = CheckboxTableViewer
+ .newCheckList(group, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE);
+ Table table = tableViewer.getTable();
+ gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 300;
+ table.setLayoutData(gd);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ String[] columnNames = new String[] { "Name", "URL" };
+ int[] columnWidths = new int[] { 200, 200 };
+
+ for (int i = 0; i < columnNames.length; i++) {
+ TableColumn tc = new TableColumn(table, SWT.LEFT);
+ tc.setText(columnNames[i]);
+ tc.setWidth(columnWidths[i]);
+ }
+
+ ColumnLayoutData[] layouts = {
+ new ColumnWeightData(200,200),
+ new ColumnWeightData(200,200)
+ };
+
+ TableLayout tableLayout = new AutoResizeTableLayout(table);
+ for (int i = 0; i < layouts.length; i++) {
+ tableLayout.addColumnData(layouts[i]);
+ }
+
+ nexusRepositories = remoteRepositoryManager.getNexusRepositories();
+ tableViewer.setLabelProvider(new NexusRepositoryLabelProvider());
+ tableViewer.setContentProvider(new NexusRepositoryContentProvider(
+ nexusRepositories));
+
+ tableViewer.setInput(nexusRepositories);
+ for (NexusRepository nexusRepository : nexusRepositories) {
+ tableViewer.setChecked(nexusRepository,
+ nexusRepository.isEnabled());
+ }
+ tableViewer.addCheckStateListener(new ICheckStateListener() {
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ NexusRepository repository = (NexusRepository) event
+ .getElement();
+ repository.setEnabled(!repository.isEnabled());
+ }
+ });
+
+ createButtons(group, tableViewer);
+ return composite;
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ }
+
+ private void createButtons(Composite parent, final TableViewer viewer) {
+ Composite buttonComposite = new Composite(parent, SWT.NONE);
+ buttonComposite.setLayout(new GridLayout(1,false));
+ buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+
+ Button addButton = new Button(buttonComposite, SWT.PUSH);
+ addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ addButton.setText("Add...");
+ addButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ EditNexusRepositoryDialog dialog = new EditNexusRepositoryDialog(getShell(), null);
+ int ok = dialog.open();
+ if (ok == Window.OK) {
+ NexusRepository repository = dialog.getNexusRepository();
+ nexusRepositories.add(repository);
+ viewer.refresh();
+ tableViewer.setChecked(repository,
+ repository.isEnabled());
+ }
+ viewer.refresh();
+ }
+
+ });
+
+ final Button editButton = new Button(buttonComposite, SWT.PUSH);
+ editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ editButton.setText("Edit...");
+ editButton.setEnabled(false);
+
+ editButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+ ISelection sel = viewer.getSelection();
+ if (sel instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) sel;
+ Object object = selection.getFirstElement();
+ if (object instanceof NexusRepository) {
+ NexusRepository repository = (NexusRepository) object;
+ NexusRepository edit = new NexusRepository(repository.getName(),
repository.getUrl(), repository.isEnabled());
+ EditNexusRepositoryDialog dialog = new EditNexusRepositoryDialog(getShell(),
edit);
+ int ok = dialog.open();
+ if (ok == Window.OK) {
+ repository.setName(edit.getName());
+ repository.setUrl(edit.getUrl());
+ repository.setEnabled(edit.isEnabled());
+ viewer.refresh();
+ tableViewer.setChecked(repository,
+ repository.isEnabled());
+ }
+ }
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ final Button removeButton = new Button(buttonComposite, SWT.PUSH);
+ removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ removeButton.setText("Remove");
+ removeButton.setEnabled(false);
+
+ removeButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+ ISelection sel = viewer.getSelection();
+ if (sel instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) sel;
+ Object object = selection.getFirstElement();
+ if (object instanceof NexusRepository) {
+ nexusRepositories.remove(object);
+ viewer.refresh();
+ }
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ final Button upButton = new Button(buttonComposite, SWT.PUSH);
+ upButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ upButton.setText("Up");
+ upButton.setEnabled(false);
+
+ final Button downButton = new Button(buttonComposite, SWT.PUSH);
+ downButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ downButton.setText("Down");
+ downButton.setEnabled(false);
+
+ upButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+ ISelection sel = viewer.getSelection();
+ if (sel instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) sel;
+ Object object = selection.getFirstElement();
+ if (object instanceof NexusRepository) {
+ NexusRepository selected = (NexusRepository) object;
+ NexusRepository[] reps = nexusRepositories.toArray(new NexusRepository[0]);
+ int selectedIndex = -1;
+ for (int i = 0; i < reps.length; i++) {
+ NexusRepository rep = reps[i];
+ if (selected.equals(rep)) {
+ selectedIndex = i;
+ break;
+ }
+ }
+ if (selectedIndex > 0) {
+ NexusRepository temp = reps[selectedIndex-1];
+ reps[selectedIndex - 1] = selected;
+ reps[selectedIndex] = temp;
+ nexusRepositories.clear();
+ for (NexusRepository repository:reps) {
+ nexusRepositories.add(repository);
+ }
+ viewer.refresh();
+ int newIndex = selectedIndex - 1;
+ downButton.setEnabled( newIndex < (reps.length - 1));
+ upButton.setEnabled(newIndex > 0);
+
+ }
+ }
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ downButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+ ISelection sel = viewer.getSelection();
+ if (sel instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) sel;
+ Object object = selection.getFirstElement();
+ if (object instanceof NexusRepository) {
+ NexusRepository selected = (NexusRepository) object;
+ NexusRepository[] reps = nexusRepositories.toArray(new NexusRepository[0]);
+ int selectedIndex = -1;
+ for (int i = 0; i < reps.length; i++) {
+ NexusRepository rep = reps[i];
+ if (selected.equals(rep)) {
+ selectedIndex = i;
+ break;
+ }
+ }
+ if (selectedIndex >= 0 && selectedIndex < reps.length) {
+ NexusRepository temp = reps[selectedIndex + 1];
+ reps[selectedIndex + 1] = selected;
+ reps[selectedIndex] = temp;
+ nexusRepositories.clear();
+ for (NexusRepository repository:reps) {
+ nexusRepositories.add(repository);
+ }
+ viewer.refresh();
+ int newIndex = selectedIndex + 1;
+ downButton.setEnabled( newIndex < (reps.length - 1));
+ upButton.setEnabled(newIndex > 0);
+ }
+ }
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection sel = viewer.getSelection();
+ if (sel instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) sel;
+ Object object = selection.getFirstElement();
+ editButton.setEnabled(object instanceof NexusRepository);
+ removeButton.setEnabled(object instanceof NexusRepository);
+ upButton.setEnabled(false);
+ downButton.setEnabled(false);
+ if (object instanceof NexusRepository && nexusRepositories.size() > 1) {
+ NexusRepository repository = (NexusRepository) object;
+ Iterator<NexusRepository> iterator = nexusRepositories.iterator();
+ NexusRepository first = null;
+ if (iterator.hasNext()) {
+ first = iterator.next();
+ }
+ NexusRepository last = null;
+ while (iterator.hasNext()) {
+ last = iterator.next();
+ }
+ if (repository.equals(last)) {
+ upButton.setEnabled(true);
+ } else if (repository.equals(first)) {
+ downButton.setEnabled(true);
+ } else {
+ upButton.setEnabled(true);
+ downButton.setEnabled(true);
+ }
+
+ }
+ } else {
+ editButton.setEnabled(false);
+ removeButton.setEnabled(false);
+ upButton.setEnabled(false);
+ downButton.setEnabled(false);
+ }
+ }
+ });
+ }
+
+ @Override
+ protected void performApply() {
+ IEclipsePreferences preferences = MavenCoreActivator.getDefault().getPreferences();
+
+ remoteRepositoryManager.setNexusRepositories(nexusRepositories);
+ remoteRepositoryManager.saveNexusRepositories();
+ MavenCoreActivator.getDefault().savePreferences();
+ tableViewer.setInput(nexusRepositories);
+ for (NexusRepository nexusRepository : nexusRepositories) {
+ tableViewer.setChecked(nexusRepository,
+ nexusRepository.isEnabled());
+ }
+ }
+
+ @Override
+ protected void performDefaults() {
+ IEclipsePreferences preferences = MavenCoreActivator.getPreferences();
+
+ remoteRepositoryManager.setNexusRepositories(null);
+ nexusRepositories = remoteRepositoryManager.getDefaultRepositories();
+ remoteRepositoryManager.saveNexusRepositories();
+ MavenCoreActivator.getDefault().savePreferences();
+ tableViewer.setInput(nexusRepositories);
+ for (NexusRepository nexusRepository : nexusRepositories) {
+ tableViewer.setChecked(nexusRepository,
+ nexusRepository.isEnabled());
+ }
+ super.performDefaults();
+ }
+
+ @Override
+ public boolean performOk() {
+ performApply();
+ return super.performOk();
+ }
+
+ private class NexusRepositoryLabelProvider extends LabelProvider implements
+ ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof NexusRepository) {
+ NexusRepository nr = (NexusRepository) element;
+ if (columnIndex == 0) {
+ return nr.getName();
+ }
+ if (columnIndex == 1) {
+ return nr.getUrl();
+ }
+ }
+ return null;
+ }
+ }
+
+ private class NexusRepositoryContentProvider implements
+ IStructuredContentProvider {
+
+ private Set<NexusRepository> repositories;
+
+ public NexusRepositoryContentProvider(Set<NexusRepository> repositories) {
+ this.repositories = repositories;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return repositories.toArray();
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ repositories = (Set<NexusRepository>) newInput;
+ }
+ }
+
+ @Override
+ public boolean performCancel() {
+ remoteRepositoryManager.setNexusRepositories(null);
+ return super.performCancel();
+ }
+}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/ConfigureMavenRepositoriesWizardPage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/ConfigureMavenRepositoriesWizardPage.java 2012-08-28
01:09:13 UTC (rev 43260)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/wizard/ConfigureMavenRepositoriesWizardPage.java 2012-08-28
09:34:41 UTC (rev 43261)
@@ -55,7 +55,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -80,7 +79,6 @@
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
-import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.index.IndexManager;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.MavenUpdateRequest;