Compare commits

...

6 Commits

Author SHA1 Message Date
Chao MENG
6775da2599 chore: fix customURIObject null issue 2020-11-20 10:08:39 +08:00
cbadillo1603
9a219873f1 fix(TBD-11038): The distribution AMAZON_EMR with the version APACHE_2_4_0_EMR doesn't exist (#3694)
* fix(TBD-11038): The distribution AMAZON_EMR with the version APACHE_2_4_0_EMR doesn't exist

* fix(TBD-11038): The distribution AMAZON_EMR with the version APACHE_2_4_0_EMR doesn't exist

* fix(TBD-11038): The distribution AMAZON_EMR with the version APACHE_2_4_0_EMR doesn't exist
2020-11-19 08:59:05 +01:00
bhe-talendbj
d013d08bdc fix(TUP-29227): Set prompt value if it is null (#3811) 2020-11-19 10:44:21 +08:00
apoltavtsev
761dcc7902 fix(TESB-29553, TESB-31088) Could not generate ctalenjob microservice jar 2020-11-18 13:27:36 +01:00
zyuan-talend
0a85c8056c TUP-28024: add automatic Nexus3 testing (#3843) 2020-11-17 10:03:29 +08:00
kjwang
3df4cf1348 Fix TUP-29290 "Detect and Update all jobs " is not identifying the changes in imported projects. (#3833)
* Fix TUP-29290 "Detect and Update all jobs " is not identifying the
changes in imported projects.
https://jira.talendforge.org/browse/TUP-29290
2020-11-16 17:33:58 +08:00
12 changed files with 659 additions and 37 deletions

View File

@@ -81,6 +81,11 @@ public final class ComponentUtilities {
public static void setNodeValue(NodeType node, String name, String value) {
ElementParameterType property = getNodeProperty(node, name);
if (property == null) {
throw new IllegalArgumentException( "The component node "+node.getComponentName()+" doesn't have the property "+name );
}
property.setValue(value);
}

View File

@@ -594,7 +594,7 @@ public class ContextUtils {
return false;
}
// need check the raw value, because in sourceParam, it's raw
if (!sourceParam.getValue().equals(targetParamType.getRawValue())) {
if (!StringUtils.equals(sourceParam.getValue(), targetParamType.getRawValue())) {
return false;
}

View File

@@ -320,7 +320,8 @@ public class JobContextManager implements IContextManager {
contextParam = new JobContextParameter();
contextParam.setContext(context);
contextParam.setName(contextParamType.getName());
contextParam.setPrompt(contextParamType.getPrompt());
contextParam.setPrompt(
contextParamType.getPrompt() == null ? (contextParamType.getName() + "?") : contextParamType.getPrompt());
contextParam.setInternalId(contextParamType.getInternalId());
originalParamerters.add(contextParam.getName());
boolean exists = true;

View File

@@ -320,24 +320,28 @@ public class RepositoryUpdateManagerHelper {
// all the jobs
for (IRepositoryViewObject process : processRep) {
Item item = process.getProperty().getItem();
boolean found = false;
for (IProcess2 open : openedProcessList) {
if (open.getId().equals(item.getProperty().getId())) {
found = true;
try {
Item item = process.getProperty().getItem();
boolean found = false;
for (IProcess2 open : openedProcessList) {
if (open.getId().equals(item.getProperty().getId())) {
found = true;
}
}
}
if (found) {
continue;
}
checkMonitorCanceled(parentMonitor);
parentMonitor.subTask(RepositoryUpdateManager.getUpdateJobInfor(item.getProperty()));
if (found) {
continue;
}
checkMonitorCanceled(parentMonitor);
parentMonitor.subTask(RepositoryUpdateManager.getUpdateJobInfor(item.getProperty()));
// List<UpdateResult> resultFromProcess = getResultFromProcess(process, types, onlySimpleShow);
// List<UpdateResult> resultFromProcess = getResultFromProcess(process, types, onlySimpleShow);
List<UpdateResult> resultFromProcess = getUpdatesNeededFromItems(parentMonitor, item, types);
if (resultFromProcess != null) {
resultList.addAll(resultFromProcess);
List<UpdateResult> resultFromProcess = getUpdatesNeededFromItems(parentMonitor, item, types);
if (resultFromProcess != null) {
resultList.addAll(resultFromProcess);
}
} catch (Exception ex) {
ExceptionHandler.process(ex);
}
parentMonitor.worked(1);
}

View File

@@ -136,7 +136,7 @@ public abstract class AbstractMavenProcessorPom extends CreateMavenBundleTemplat
Map<ETalendMavenVariables, String> variablesValuesMap = new HashMap<ETalendMavenVariables, String>();
// no need check property is null or not, because if null, will get default ids.
JobInfo lastMainJob = LastGenerationInfo.getInstance().getLastMainJob();
JobInfo lastMainJob = LastGenerationInfo.getInstance().getLastMainJob();
if (JobUtils.isJob(property) && ProcessUtils.isChildRouteProcess(process) && lastMainJob != null) {
variablesValuesMap.put(ETalendMavenVariables.JobGroupId, PomIdsHelper.getJobGroupId(lastMainJob.getProcessor().getProperty()));
variablesValuesMap.put(ETalendMavenVariables.JobVersion, PomIdsHelper.getJobVersion(lastMainJob.getProcessor().getProperty()));
@@ -318,10 +318,18 @@ public abstract class AbstractMavenProcessorPom extends CreateMavenBundleTemplat
String type = null;
if (!jobInfo.isJoblet()) {
property = jobInfo.getProcessItem().getProperty();
groupId = PomIdsHelper.getJobGroupId(property);
artifactId = PomIdsHelper.getJobArtifactId(jobInfo);
JobInfo lastMainJob = LastGenerationInfo.getInstance().getLastMainJob();
if (lastMainJob != null && JobUtils.isJob(jobInfo)) {
groupId = PomIdsHelper.getJobGroupId(lastMainJob.getProcessor().getProperty());
version = PomIdsHelper.getJobVersion(lastMainJob.getProcessor().getProperty());
} else {
groupId = PomIdsHelper.getJobGroupId(property);
version = PomIdsHelper.getJobVersion(property);
}
version = PomIdsHelper.getJobVersion(property);
// try to get the pom version of children job and load from the pom file.
String childPomFileName = PomUtil.getPomFileName(jobInfo.getJobName(), jobInfo.getJobVersion());
IProject codeProject = getJobProcessor().getCodeProject();

View File

@@ -28,6 +28,7 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -60,10 +61,25 @@ public class CustomUriManager {
private final Object reloadingLock = new Object();
private CustomUriManager() {
IFolder resourcePath = getResourcePath();
try {
customURIObject = loadResources(getResourcePath(), RepositoryConstants.PROJECT_SETTINGS_CUSTOM_URI_MAP);
Assert.isNotNull(resourcePath);
customURIObject = loadResources(resourcePath, RepositoryConstants.PROJECT_SETTINGS_CUSTOM_URI_MAP);
} catch (Exception e) {
ExceptionHandler.process(e);
try {
if (resourcePath != null) {
customURIObject = loadResources(resourcePath.getLocation().toPortableString(),
RepositoryConstants.PROJECT_SETTINGS_CUSTOM_URI_MAP);
}
} catch (Exception e1) {
ExceptionHandler.process(e1);
/**
* Seems dangrous to load an empty json here, because it may overwrite the existing one
*/
// customURIObject = new JSONObject();
}
}
}
@@ -263,10 +279,14 @@ public class CustomUriManager {
public void reloadCustomMapping() {
try {
if (isNeedReload) {
if (isNeedReload || customURIObject == null) {
synchronized (reloadingLock) {
if (isNeedReload) {
customURIObject.clear();
if (isNeedReload || customURIObject == null) {
if (customURIObject == null) {
customURIObject = new JSONObject();
} else {
customURIObject.clear();
}
JSONObject loadResources = loadResources(getResourcePath(),
RepositoryConstants.PROJECT_SETTINGS_CUSTOM_URI_MAP);
customURIObject.putAll(loadResources);

View File

@@ -1,12 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.talend.studio</groupId>
<artifactId>tcommon-studio-se</artifactId>
<version>7.3.1-PATCH</version>
<relativePath>../../../</relativePath>
</parent>
<artifactId>org.talend.librariesmanager.test</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.talend.studio</groupId>
<artifactId>tcommon-studio-se</artifactId>
<version>7.3.1-PATCH</version>
<relativePath>../../../</relativePath>
</parent>
<artifactId>org.talend.librariesmanager.test</artifactId>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.talend.studio.test</groupId>
<artifactId>nexus.upload.test.new</artifactId>
<version>1.0.0</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.talend.studio.test</groupId>
<artifactId>nexus.upload.test.new</artifactId>
<version>1.0.0</version>
<type>dll</type>
</dependency>
<dependency>
<groupId>org.talend.studio.test</groupId>
<artifactId>nexus.upload.test.new</artifactId>
<version>1.0.0</version>
<type>exe</type>
</dependency>
<dependency>
<groupId>org.talend.studio.test</groupId>
<artifactId>nexus.upload.test.new</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.talend.studio.test</groupId>
<artifactId>nexus.upload.test.old</artifactId>
<version>1.0.0</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.talend.studio.test</groupId>
<artifactId>nexus.upload.test.old</artifactId>
<version>1.0.0</version>
<type>dll</type>
</dependency>
<dependency>
<groupId>org.talend.studio.test</groupId>
<artifactId>nexus.upload.test.old</artifactId>
<version>1.0.0</version>
<type>exe</type>
</dependency>
<dependency>
<groupId>org.talend.studio.test</groupId>
<artifactId>nexus.upload.test.old</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.talend.studio.test</includeGroupIds>
<copyPom>true</copyPom>
<includeArtifactIdIds>nexus.upload.test.old,nexus.upload.test.new</includeArtifactIdIds>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>${project.basedir}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,5 @@
rep.create.endpoint=/service/rest/v1/repositories/maven/hosted
rep.list.endpoint=/service/rest/v1/repositories/maven/hosted/{repid}
component.search.endpoint=/service/rest/v1/search
component.delete.endpoint=/service/rest/v1/components/{id}
component.upload.command=curl -v -u {user}:{password} -X POST \"{server}/service/rest/v1/components?repository={repid}\" -F maven2.groupId={groupid} -F maven2.artifactId={artifactid} -F maven2.version={version} -F maven2.asset1=@{filepath} -F maven2.asset1.extension={fileext}

View File

@@ -0,0 +1,18 @@
{
"name": "NEWREPNAME",
"online": true,
"storage": {
"blobStoreName": "default",
"strictContentTypeValidation": false,
"writePolicy": "ALLOW"
},
"cleanup": {
"policyNames": [
"string"
]
},
"maven": {
"versionPolicy": "NEWVERSIONPOLICY",
"layoutPolicy": "STRICT"
}
}

View File

@@ -12,17 +12,72 @@
// ============================================================================
package org.talend.librariesmanager.nexus;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;
import org.apache.commons.codec.digest.DigestUtils;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.talend.core.nexus.ArtifactRepositoryBean;
import org.talend.core.nexus.IRepositoryArtifactHandler;
import org.talend.core.nexus.NexusServerUtils;
import org.talend.core.nexus.RepositoryArtifactHandlerManager;
import org.talend.core.nexus.TalendMavenResolver;
import org.talend.core.nexus.ArtifactRepositoryBean.NexusType;
import org.talend.core.runtime.CoreRuntimePlugin;
import org.talend.core.runtime.maven.MavenArtifact;
import org.talend.core.runtime.maven.MavenUrlHelper;
import org.talend.librariesmanager.model.service.LocalLibraryManager;
import org.talend.librariesmanager.nexus.utils.NexusServerManagerProxy;
import org.talend.librariesmanager.nexus.utils.RestAPIUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* created by wchen on Aug 18, 2017 Detailled comment
*
*/
public class Nexus3RepositoryHandlerTest {
private static Properties nexusprops = new Properties();
private static ArtifactRepositoryBean customNexusServer;
private static IRepositoryArtifactHandler repHandler;
private static String[] types = new String[] {"jar", "pom", "exe", "zip", "dll"};
@BeforeClass
public static void init() throws FileNotFoundException, IOException {
URL entry = Platform.getBundle("org.talend.librariesmanager.test").getEntry("resources/nexus/nexus3.properties");
nexusprops.load(new FileInputStream(FileLocator.toFileURL(entry).getFile()));
customNexusServer = NexusServerManagerProxy.getInstance().getCustomNexusServer();
repHandler = RepositoryArtifactHandlerManager.getRepositoryHandler(customNexusServer);
createNexusRepository(customNexusServer.getRepositoryId(),"RELEASE");
createNexusRepository(customNexusServer.getSnapshotRepId(),"SNAPSHOT");
}
@Test
public void testGetRepositoryURL() {
ArtifactRepositoryBean serverBean = new ArtifactRepositoryBean();
@@ -37,5 +92,329 @@ public class Nexus3RepositoryHandlerTest {
String snapshotUrl = handler.getRepositoryURL(false);
Assert.assertEquals("http://localhost:8081/repository/snapshot-repository/", snapshotUrl);
}
@Test
public void testCheckConnectionOK() {
Assert.assertTrue(repHandler.checkConnection());
}
@Test
public void testCheckConnectionFalse() {
ArtifactRepositoryBean dummyNexusServer = NexusServerManagerProxy.getInstance().getDummyNexusServer();
IRepositoryArtifactHandler repHandler = RepositoryArtifactHandlerManager.getRepositoryHandler(dummyNexusServer);
Assert.assertFalse(repHandler.checkConnection());
}
@Test
public void testDeployOnSnapshot() throws Exception {
for ( String type : types ) {
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/" + type;
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
try {
clearLocalFile(uri);
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0." + type);
File originalJarFile = new File(FileLocator.toFileURL(entry).getFile());
String originalSHA1 = getSha1(originalJarFile);
// deploy the file to nexus
repHandler.deploy(originalJarFile, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), type, artifact.getVersion());
File reolved = repHandler.resolve(artifact);
assertEquals(originalSHA1,getSha1(reolved));
} finally {
deleteNexusArtifact(artifact, false, true);
}
}
}
@Test
public void testDeployOnRelease() throws Exception {
for ( String type : types ) {
String uri = "mvn:org.talend.libraries/test/6.0.0/" + type ;
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
try {
clearLocalFile(uri);
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0." + type);
File originalJarFile = new File(FileLocator.toFileURL(entry).getFile());
String originalSHA1 = getSha1(originalJarFile);
// deploy file to nexus
repHandler.deploy(originalJarFile, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), type , artifact.getVersion());
File resolved = repHandler.resolve(artifact);
assertEquals(originalSHA1,getSha1(resolved));
} finally {
deleteNexusArtifact(artifact, true, true);
}
}
}
@Test
public void testUpdateOnSnapshot() throws Exception {
for ( String type : types ) {
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/" + type ;
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
try {
clearLocalFile(uri);
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0." + type);
File originalJarFile = new File(FileLocator.toFileURL(entry).getFile());
entry = bundle.getEntry("/lib/nexus.upload.test.new-1.0.0." + type);
File newJarFile = new File(FileLocator.toFileURL(entry).getFile());
String originalSHA1 = getSha1(originalJarFile);
String newJarSHA1 = getSha1(newJarFile);
// deploy original jar without resolving
repHandler.deploy(originalJarFile, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), type, artifact.getVersion());
//deploy new jar
repHandler.deploy(newJarFile, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), type, artifact.getVersion());
//resolve and check the local file
File resolved = repHandler.resolve(artifact);
assertEquals(newJarSHA1,getSha1(resolved));
} finally {
deleteNexusArtifact(artifact, false, true);
}
}
}
@Test
public void testResolveSha1NotExist() throws Exception {
String uri = "mvn:org.talend.libraries/not-existing/6.0.0-SNAPSHOT/jar";
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
try {
File f = repHandler.resolve(artifact);
assertNull(f);
} catch (FileNotFoundException fnfe) {
//It is one expected exception.
return;
}
}
@Test
public void testSearchOnRelease() throws Exception {
for (String type: types) {
String uri = "mvn:org.talend.libraries/test/6.0.0/" + type;
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
try {
//Step1:Prepare the installed artifact
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
final URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0." + type);
File fileToBeInstalled = new File(FileLocator.toFileURL(entry).getFile());
//Step2:Search empty
List<MavenArtifact> searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), true, false);
if ( searchRet != null && searchRet.size() > 0 ) {
Assert.fail("The artifact:" + uri + " is not expected to intalled before the test");
}
//Step3:Deploy the artifact
repHandler.deploy(fileToBeInstalled, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), artifact.getVersion());
//Step4:Verify the search result
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), true, false);
int i = 30;
while ( searchRet.size() < 1 && i > 0 ) {
Thread.sleep(1000);
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), true, false);
i--;
}
if (NexusServerUtils.IGNORED_TYPES.contains(type)) {
assertEquals("Should get 0 artifact when searching for ignored type of " + uri , 0, searchRet.size());
} else {
assertEquals("Should get 1 artifact when searching for " + uri , 1, searchRet.size());
assertEquals(artifact.getArtifactId(), searchRet.get(0).getArtifactId());
assertEquals(artifact.getGroupId(), searchRet.get(0).getGroupId());
assertEquals(artifact.getVersion(), searchRet.get(0).getVersion());
assertEquals(artifact.getClassifier(), searchRet.get(0).getClassifier());
assertEquals(artifact.getType(), searchRet.get(0).getType());
}
} finally {
deleteNexusArtifact(artifact, true, true);
Thread.sleep(1000);
}
}
}
@Test
public void testSearchOnSnapshot() throws Exception {
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/jar";
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
try {
//Step1:Prepare the installed artifact
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
final URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0.jar");
File fileToBeInstalled = new File(FileLocator.toFileURL(entry).getFile());
//Step2:Search empty
List<MavenArtifact> searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
if ( searchRet != null && searchRet.size() > 0 ) {
Assert.fail("The artifact is not expected to intalled before the test");
}
//Step3:Deploy the artifact
repHandler.deploy(fileToBeInstalled, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "jar", artifact.getVersion());
//Step4:Verify the search result
//In snapshot repository, Timestamp is added in item version like 6.0.0-20201102.054042-1,
//the search result for given version like 6.0.0 will be empty. Currently the version will not be given in search criteria.
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
int i = 30;
while ( searchRet.size() < 1 && i > 0 ) {
Thread.sleep(1000);
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
i--;
}
debug("testSearchSnapshot:" + searchRet);
assertEquals(1, searchRet.size());
assertEquals(artifact.getArtifactId(), searchRet.get(0).getArtifactId());
assertEquals(artifact.getGroupId(), searchRet.get(0).getGroupId());
//assertEquals(artifact.getVersion(), searchRet.get(0).getVersion());
assertEquals(artifact.getClassifier(), searchRet.get(0).getClassifier());
assertEquals(artifact.getType(), searchRet.get(0).getType());
} finally {
deleteNexusArtifact(artifact, false, true);
Thread.sleep(1000);
}
}
@Test
public void testPaginationSearchOnSnapshot() throws Exception {
//Pagination is enabled by Nexus when a search returns 50 results
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/zip";
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
List<MavenArtifact> searchRet = new ArrayList<MavenArtifact>();
try {
//Step1:Prepare the installed artifact
Bundle bundle = Platform.getBundle("org.talend.librariesmanager.test");
final URL entry = bundle.getEntry("/lib/nexus.upload.test.old-1.0.0.zip");
File fileToBeInstalled = new File(FileLocator.toFileURL(entry).getFile());
//Step2:Deploy the artifacts for 101 times on snapshot repository .
int i = 51;
while ( i> 0 ) {
repHandler.deploy(fileToBeInstalled, artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "zip", artifact.getVersion());
i--;
}
//Step3:Verify the search result. It will take some time for the deployment and wait for most 60 seconds
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
i = 6;
while ( searchRet.size() < 51 && i > 0 ) {
Thread.sleep(10000);
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
i--;
}
assertEquals(51, searchRet.size());
} finally {
deleteNexusArtifacts(searchRet, false, true);
}
}
//@Test
public void testUpdateMavenResolver() throws InvalidSyntaxException, IOException {
Dictionary<String, String> props = new Hashtable<String, String>();
props.put("org.ops4j.pax.url.mvn.socket.readTimeout", "59");
props.put("org.ops4j.pax.url.mvn.socket.connectionTimeout", "119");
repHandler.updateMavenResolver(TalendMavenResolver.TALEND_ARTIFACT_LIBRARIES_RESOLVER, props);
BundleContext context = CoreRuntimePlugin.getInstance().getBundle().getBundleContext();
ServiceReference ca = context.getServiceReference(ConfigurationAdmin.class);
debug("" + ca);
ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getService(ca);
if ( configAdmin == null ) {
Configuration conf = configAdmin.getConfiguration("(service.pid=org.ops4j.pax.url.mvn)");
assertEquals("59", conf.getProperties().get("org.ops4j.pax.url.mvn.socket.readTimeout"));
assertEquals("119", conf.getProperties().get("org.ops4j.pax.url.mvn.socket.connectionTimeout"));
}
}
@Before
@After
public void cleanup() {
try {
String uri = "mvn:org.talend.libraries/test/6.0.0-SNAPSHOT/jar";
MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(uri);
List<MavenArtifact> searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, false, true);
deleteNexusArtifacts(searchRet,false,true);
uri = "mvn:org.talend.libraries/test/6.0.0/jar";
artifact = MavenUrlHelper.parseMvnUrl(uri);
searchRet = repHandler.search(artifact.getGroupId(), artifact.getArtifactId(), null, true, false);
deleteNexusArtifacts(searchRet,true,true);
} catch ( Exception ex ) {
}
}
private void clearLocalFile(String uri) {
LocalLibraryManager localLibraryManager = new LocalLibraryManager();
String localJarPath = localLibraryManager.getJarPathFromMaven(uri);
debug("localJarPath:" + localJarPath);
// force to delete the file to have a valid test
if (localJarPath != null) {
org.talend.utils.io.FilesUtils.deleteFolder(new File(localJarPath).getParentFile().getParentFile(), true);
}
// file should not exist anymore
assertNull(localLibraryManager.getJarPathFromMaven(uri));
}
private static void createNexusRepository(String repId,String versionPolicy) throws IOException {
if (!"SNAPSHOT".equalsIgnoreCase(versionPolicy) && !"RELEASE".equalsIgnoreCase(versionPolicy)) {
Assert.fail("Repository Version Policy must be SNAPSHOT OR RELEASE, but got " + versionPolicy);
}
String getstmt = customNexusServer.getServer() +
nexusprops.getProperty("rep.list.endpoint").replace("{repid}", repId);
try {
String[] response = RestAPIUtil.doRequest(getstmt, "GET", customNexusServer.getUserName(), customNexusServer.getPassword(), null);
if ( response[0].equals("200")) return;
} catch (Exception ex ) {
//Can not find and will create a new one
debug("Can not find the repository named as " + repId + " and will create a new one :" + ex.getMessage());
}
String createstmt = customNexusServer.getServer() + nexusprops.getProperty("rep.create.endpoint");
String jsonfilepath = FileLocator.toFileURL(Platform.getBundle("org.talend.librariesmanager.test").getEntry("resources/nexus/nexus3_create_rep.json")).getFile();
String data = new String(Files.readAllBytes(new File(jsonfilepath).toPath())).replace("NEWREPNAME", repId).replace("NEWVERSIONPOLICY", versionPolicy.toUpperCase());
try {
String[] response = RestAPIUtil.doRequest(createstmt, "POST", customNexusServer.getUserName(), customNexusServer.getPassword(), data);
if ( response[0].equals("201")) debug("Created the test repository successfully!");
} catch (Exception ex ) {
debug("Exception when create the repository of " + repId + ":" + ex );
}
}
private static void deleteNexusArtifacts( List<MavenArtifact> artifacts,boolean isRelease, boolean skiperror) throws Exception{
if (artifacts == null) return;
for (MavenArtifact artifact : artifacts) {
deleteNexusArtifact(artifact,isRelease,skiperror);
}
}
private static void deleteNexusArtifact(MavenArtifact artifact, boolean fromRelease, boolean skiperror) throws Exception {
try {
StringBuffer searchstmt = new StringBuffer();
searchstmt.append(customNexusServer.getServer())
.append(nexusprops.getProperty("component.search.endpoint"))
.append("?repository=").append( fromRelease ? customNexusServer.getRepositoryId() : customNexusServer.getSnapshotRepId())
.append("&group=").append(artifact.getGroupId())
.append("&name=").append(artifact.getArtifactId());
if ( !artifact.getVersion().endsWith(MavenUrlHelper.VERSION_SNAPSHOT))
searchstmt.append("&version=").append(artifact.getVersion());
String[] resp = RestAPIUtil.doRequest(searchstmt.toString(), "GET", customNexusServer.getUserName(), customNexusServer.getPassword(), null);
if ( !resp[0].equals("200")) return;
JSONObject obj = JSONObject.fromObject(resp[1]);
JSONArray items = obj.getJSONArray("items");
if ( items.size() < 1) return;
JSONObject item = (JSONObject) items.get(0);
String componentid = item.getString("id");
String deltestmt = customNexusServer.getServer() + nexusprops.getProperty("component.delete.endpoint").replace("{id}", componentid);
RestAPIUtil.doRequest(deltestmt, "DELETE", customNexusServer.getUserName(), customNexusServer.getPassword(), null);
} catch (Exception ex) {
if (!skiperror) throw ex;
}
}
private String getSha1(File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
String sha1 = DigestUtils.shaHex(fis);
fis.close();
return sha1;
}
private String getSha1(String file) throws IOException {
return getSha1(new File(file));
}
private static void debug(String message) {
System.out.println("[DEBUG]:" + message);
}
}

View File

@@ -0,0 +1,52 @@
package org.talend.librariesmanager.nexus.utils;
import java.util.Properties;
import org.talend.core.nexus.ArtifactRepositoryBean;
import org.talend.core.nexus.IRepositoryArtifactHandler;
import org.talend.core.nexus.RepositoryArtifactHandlerManager;
public class NexusServerManagerProxy {
private static String NEXUS_USER = "nexus.user";
private static String NEXUS_PASSWORD = "nexus.password";
private static String NEXUS_URL = "nexus.url";
private static String NEXUS_LIB_REPO = "nexus.lib.repo";
private static String NEXUS_LIB_SNAPSHOT_REPO = "nexus.lib.repo.snapshot";
private static String DEFAULT_LIB_REPO = "rep-for-test-releases";
private static String DEFAULT_LIB_SNAPSHOT_REPO = "rep-for-test-snapshots";
private static String NEXUS_LIB_SERVER_TYPE = "nexus.lib.server.type";
private static Properties props;
private static NexusServerManagerProxy manager = null;
public static synchronized NexusServerManagerProxy getInstance() {
if (manager == null) {
manager = new NexusServerManagerProxy();
}
return manager;
}
public ArtifactRepositoryBean getCustomNexusServer() {
String nexus_url = System.getProperty(NEXUS_URL);
String nexus_user = System.getProperty(NEXUS_USER);
String nexus_pass = System.getProperty(NEXUS_PASSWORD);
String repositoryId = System.getProperty(NEXUS_LIB_REPO, DEFAULT_LIB_REPO);
String snapshotRepId = System.getProperty(NEXUS_LIB_SNAPSHOT_REPO, DEFAULT_LIB_SNAPSHOT_REPO);
String serverType = System.getProperty(NEXUS_LIB_SERVER_TYPE, "NEXUS_3");
ArtifactRepositoryBean serverBean = new ArtifactRepositoryBean();
serverBean.setServer(nexus_url);
serverBean.setUserName(nexus_user);
serverBean.setPassword(nexus_pass);
serverBean.setRepositoryId(repositoryId);
serverBean.setSnapshotRepId(snapshotRepId);
serverBean.setType(serverType);
return serverBean;
}
public ArtifactRepositoryBean getDummyNexusServer() {
ArtifactRepositoryBean serverBean = getCustomNexusServer();
serverBean.setServer("http://localhost:0000");
return serverBean;
}
}

View File

@@ -0,0 +1,57 @@
package org.talend.librariesmanager.nexus.utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class RestAPIUtil {
public static String[] doRequest(String uri, String httpmethod, String user, String password, String data)
throws Exception {
String[] ret = new String[2];
StringBuffer response = new StringBuffer();
URL url = new URL(uri);
String auth = user + ":" + password;
try {
byte[] encodedAuth = Base64.getEncoder().encode((auth.getBytes(StandardCharsets.UTF_8)));
String authHeaderValue = "Basic " + new String(encodedAuth);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", authHeaderValue);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestMethod(httpmethod);
if (data != null) {
conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect();
try (OutputStreamWriter streamWriter = new OutputStreamWriter(conn.getOutputStream());) {
streamWriter.write(data);
streamWriter.flush();
}
}
int responsecode = conn.getResponseCode();
debug(responsecode + " is returned for " + httpmethod + " on the endpoint:" + uri);
ret[0] = Integer.toString(responsecode);
try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"))) {
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
}
ret[1] = response.toString();
conn.disconnect();
} catch (Exception ex) {
debug(ex.getMessage());
throw ex;
}
return ret;
}
private static void debug(String message) {
System.out.println("[DEBUG]:" + message);
}
}