Compare commits
12 Commits
msheverda_
...
onimych/TD
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2559c2af73 | ||
|
|
e39d7ea3dc | ||
|
|
c628e574a9 | ||
|
|
6d6737ea18 | ||
|
|
120a8e859f | ||
|
|
d0e8130b62 | ||
|
|
7b21a63ff4 | ||
|
|
71a93464d3 | ||
|
|
1ccaf1f6d9 | ||
|
|
a8aa387a65 | ||
|
|
a694ceed1d | ||
|
|
737d27ccf9 |
@@ -13,6 +13,8 @@
|
||||
package org.talend.core.repository.ui.dialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -30,12 +32,14 @@ import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.talend.commons.exception.PersistenceException;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.model.properties.Item;
|
||||
import org.talend.core.model.properties.ProcessItem;
|
||||
import org.talend.core.model.properties.Property;
|
||||
import org.talend.core.model.repository.IRepositoryObject;
|
||||
import org.talend.core.model.repository.IRepositoryViewObject;
|
||||
import org.talend.core.repository.utils.RepositoryNodeSortUtil;
|
||||
import org.talend.core.ui.ITestContainerProviderService;
|
||||
import org.talend.repository.model.RepositoryNode;
|
||||
import org.talend.repository.model.IRepositoryNode.EProperties;
|
||||
@@ -107,7 +111,8 @@ public class PastSelectorDialog extends Dialog {
|
||||
modificationTime.setWidth(200);
|
||||
modificationTime.setText("Modification Time");
|
||||
|
||||
for (IRepositoryViewObject object : versions) {
|
||||
RepositoryNodeSortUtil util = new RepositoryNodeSortUtil();
|
||||
for (IRepositoryViewObject object : util.getSortVersion(versions)) {
|
||||
TableItem item = new TableItem(table, SWT.NONE);
|
||||
item.setData(object);
|
||||
item.setText(0, object.getVersion());
|
||||
@@ -187,7 +192,7 @@ public class PastSelectorDialog extends Dialog {
|
||||
});
|
||||
return composite;
|
||||
}
|
||||
|
||||
|
||||
public Set<IRepositoryViewObject> getSelectedVersionItems() {
|
||||
return this.selectedVersionItems;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.core.repository.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.talend.commons.utils.Version;
|
||||
import org.talend.core.model.repository.IRepositoryViewObject;
|
||||
|
||||
/**
|
||||
* @author hwang
|
||||
*
|
||||
*/
|
||||
public class RepositoryNodeSortUtil {
|
||||
|
||||
public List<IRepositoryViewObject> getSortVersion(List<IRepositoryViewObject> versions) {
|
||||
List<IRepositoryViewObject> temp = new ArrayList<IRepositoryViewObject>();
|
||||
temp.addAll(versions);
|
||||
|
||||
Collections.sort(temp, new Comparator<IRepositoryViewObject>() {
|
||||
|
||||
@Override
|
||||
public int compare(IRepositoryViewObject o1, IRepositoryViewObject o2) {
|
||||
String version1 = o1.getVersion();
|
||||
String version2 = o2.getVersion();
|
||||
if(version1 != null && version2 != null) {
|
||||
return new Version(version1).compareTo(new Version(version2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,6 @@ public class ModuleNeeded {
|
||||
|
||||
public static final String UNKNOWN = "Unknown";
|
||||
|
||||
public static final String ASSEMBLY_OPTIONAL = "ASSEMBLY_OPTIONAL"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* TODO This is a hot fix for 7.2.1 . if the maven url is not specified in component/extension point , we will
|
||||
* generate a release version with this flag=true .Need to improve it after release ,normally the studio should use
|
||||
|
||||
@@ -529,6 +529,11 @@ public class ERepositoryObjectType extends DynaEnum<ERepositoryObjectType> {
|
||||
*/
|
||||
public final static ERepositoryObjectType PROCESS_ROUTE = ERepositoryObjectType.valueOf("ROUTE"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* <font color="red">This value may be <b>null</b> in some licenses, <b>should add NPE check</b></font>
|
||||
*/
|
||||
public final static ERepositoryObjectType PROCESS_ROUTE_DESIGN = ERepositoryObjectType.valueOf("ROUTE_DESIGNS");
|
||||
|
||||
/**
|
||||
* <font color="red">This value may be <b>null</b> in some licenses, <b>should add NPE check</b></font>
|
||||
*/
|
||||
|
||||
@@ -98,6 +98,7 @@ import org.talend.core.model.utils.UpdateRepositoryHelper;
|
||||
import org.talend.core.prefs.ITalendCorePrefConstants;
|
||||
import org.talend.core.runtime.CoreRuntimePlugin;
|
||||
import org.talend.core.runtime.i18n.Messages;
|
||||
import org.talend.core.runtime.services.IGenericDBService;
|
||||
import org.talend.core.service.IMRProcessService;
|
||||
import org.talend.core.service.IMetadataManagmentService;
|
||||
import org.talend.core.service.IStormProcessService;
|
||||
@@ -690,10 +691,15 @@ public abstract class RepositoryUpdateManager {
|
||||
Set<String> set = valueMap.keySet();
|
||||
List<String> list = new ArrayList<String>(set);
|
||||
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
|
||||
boolean foundCompProperties = false;
|
||||
ConnectionItem dbConnectionItem = null;
|
||||
Map<String, String> oldToNewHM = new HashMap<String, String>();
|
||||
|
||||
for (String newValue : list) {
|
||||
String oldValue = valueMap.get(newValue);
|
||||
oldValue = "context." + oldValue;
|
||||
newValue = "context." + newValue;
|
||||
oldToNewHM.put(oldValue, newValue);
|
||||
List<IRepositoryViewObject> dbConnList = factory.getAll(ERepositoryObjectType.METADATA_CONNECTIONS, true);
|
||||
for (IRepositoryViewObject obj : dbConnList) {
|
||||
Item item = obj.getProperty().getItem();
|
||||
@@ -707,6 +713,11 @@ public abstract class RepositoryUpdateManager {
|
||||
if (citem == contextItem) {
|
||||
if (conn instanceof DatabaseConnection) {
|
||||
DatabaseConnection dbConn = (DatabaseConnection) conn;
|
||||
String compProperties = dbConn.getCompProperties();
|
||||
if (!foundCompProperties && StringUtils.isNotBlank(compProperties)) {
|
||||
foundCompProperties = true;
|
||||
dbConnectionItem = (ConnectionItem) item;
|
||||
}
|
||||
if (dbConn.getAdditionalParams() != null && dbConn.getAdditionalParams().equals(oldValue)) {
|
||||
dbConn.setAdditionalParams(newValue);
|
||||
} else if (dbConn.getUsername() != null && dbConn.getUsername().equals(oldValue)) {
|
||||
@@ -1098,6 +1109,11 @@ public abstract class RepositoryUpdateManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (foundCompProperties && GlobalServiceRegister.getDefault().isServiceRegistered(IGenericDBService.class)) {
|
||||
IGenericDBService service = GlobalServiceRegister.getDefault().getService(IGenericDBService.class);
|
||||
service.updateCompPropertiesForContextMode(dbConnectionItem.getConnection(), oldToNewHM);
|
||||
factory.save(dbConnectionItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateParameters(DatabaseConnection dbConn, String oldValue, String newValue) {
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.talend.core.model.general.ModuleNeeded;
|
||||
import org.talend.core.model.process.JobInfo;
|
||||
@@ -33,6 +32,8 @@ public class LastGenerationInfo {
|
||||
|
||||
private HashMap<String, Set<ModuleNeeded>> modulesNeededWithSubjobPerJob;
|
||||
|
||||
private HashMap<String, Set<ModuleNeeded>> highPriorityModuleNeededPerJob;
|
||||
|
||||
private HashMap<String, Set<ModuleNeeded>> highPriorityModuleNeeded;
|
||||
|
||||
private HashMap<String, Set<ModuleNeeded>> testcaseModuleNeeded;
|
||||
@@ -55,6 +56,7 @@ public class LastGenerationInfo {
|
||||
modulesNeededPerJob = new HashMap<String, Set<ModuleNeeded>>();
|
||||
contextPerJob = new HashMap<String, Set<String>>();
|
||||
modulesNeededWithSubjobPerJob = new HashMap<String, Set<ModuleNeeded>>();
|
||||
highPriorityModuleNeededPerJob = new HashMap<>();
|
||||
highPriorityModuleNeeded = new HashMap<>();
|
||||
testcaseModuleNeeded = new HashMap<>();
|
||||
lastGeneratedjobs = new HashSet<JobInfo>();
|
||||
@@ -239,6 +241,22 @@ public class LastGenerationInfo {
|
||||
return routinesNeededPerJob.get(key);
|
||||
}
|
||||
|
||||
public Set<ModuleNeeded> getHighPriorityModuleNeededPerJob(String jobId, String jobVersion) {
|
||||
String key = getProcessKey(jobId, jobVersion);
|
||||
if (!highPriorityModuleNeededPerJob.containsKey(key)) {
|
||||
highPriorityModuleNeededPerJob.put(key, new LinkedHashSet<>());
|
||||
}
|
||||
return highPriorityModuleNeededPerJob.get(key);
|
||||
}
|
||||
|
||||
public void setHighPriorityModuleNeededPerJob(String jobId, String jobVersion, Set<ModuleNeeded> moduleNeeded) {
|
||||
String key = getProcessKey(jobId, jobVersion);
|
||||
if (!highPriorityModuleNeededPerJob.containsKey(key)) {
|
||||
highPriorityModuleNeededPerJob.put(key, new LinkedHashSet<>());
|
||||
}
|
||||
highPriorityModuleNeededPerJob.get(key).addAll(moduleNeeded);
|
||||
}
|
||||
|
||||
public Set<ModuleNeeded> getHighPriorityModuleNeeded(String jobId, String jobVersion) {
|
||||
String key = getProcessKey(jobId, jobVersion);
|
||||
if (!highPriorityModuleNeeded.containsKey(key)) {
|
||||
@@ -264,12 +282,11 @@ public class LastGenerationInfo {
|
||||
}
|
||||
|
||||
public void setTestcaseModuleNeeded(String jobId, String jobVersion, Set<ModuleNeeded> modulesNeeded) {
|
||||
Set<ModuleNeeded> set = modulesNeeded.stream().map(m -> m.clone())
|
||||
.peek(m -> m.getExtraAttributes().put(ModuleNeeded.ASSEMBLY_OPTIONAL, true)).collect(Collectors.toSet());
|
||||
testcaseModuleNeeded.put(getProcessKey(jobId, jobVersion), set);
|
||||
testcaseModuleNeeded.put(getProcessKey(jobId, jobVersion), new HashSet<>(modulesNeeded));
|
||||
}
|
||||
|
||||
public void clearHighPriorityModuleNeeded() {
|
||||
highPriorityModuleNeededPerJob.clear();
|
||||
highPriorityModuleNeeded.clear();
|
||||
}
|
||||
|
||||
@@ -321,7 +338,7 @@ public class LastGenerationInfo {
|
||||
modulesNeededPerJob.clear();
|
||||
routinesNeededPerJob.clear();
|
||||
modulesNeededWithSubjobPerJob.clear();
|
||||
highPriorityModuleNeeded.clear();
|
||||
clearHighPriorityModuleNeeded();
|
||||
testcaseModuleNeeded.clear();
|
||||
routinesNeededWithSubjobPerJob.clear();
|
||||
contextPerJob.clear();
|
||||
|
||||
@@ -64,4 +64,6 @@ public interface IGenericDBService extends IService{
|
||||
|
||||
public ERepositoryObjectType getExtraDBType(ERepositoryObjectType type);
|
||||
|
||||
public void updateCompPropertiesForContextMode(Connection connection, Map<String, String> contextVarMap);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2006-2020 Talend Inc. - www.talend.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
package org.talend.core.service;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.talend.core.IService;
|
||||
import org.talend.core.model.components.IComponent;
|
||||
import org.talend.core.model.properties.Item;
|
||||
|
||||
/**
|
||||
* For documentation, see implementation in org.talend.sdk.component.studio-integration plugin
|
||||
*/
|
||||
public interface ITaCoKitDependencyService extends IService {
|
||||
|
||||
boolean hasTaCoKitComponents(final Stream<IComponent> components);
|
||||
|
||||
Set<String> getTaCoKitOnlyDependencies(final Stream<IComponent> components);
|
||||
|
||||
Stream<IComponent> getJobComponents(Item item);
|
||||
|
||||
Path findM2Path();
|
||||
}
|
||||
@@ -281,6 +281,17 @@ public final class TalendQuoteUtils {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static boolean isEnclosed(String text) {
|
||||
if (text == null) {
|
||||
return false;
|
||||
}
|
||||
text = text.trim();
|
||||
if (text.length() < 2) {
|
||||
return false;
|
||||
}
|
||||
return text.startsWith(QUOTATION_MARK) && text.endsWith(QUOTATION_MARK);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* ggu Comment method "addQuotesForSQLString".
|
||||
|
||||
@@ -477,6 +477,10 @@ public class TalendTextUtils {
|
||||
return TalendQuoteUtils.removeQuotes(text, quotation);
|
||||
}
|
||||
|
||||
public static boolean isEnclosed(String text) {
|
||||
return TalendQuoteUtils.isEnclosed(text);
|
||||
}
|
||||
|
||||
public static String getStringConnect() {
|
||||
return TalendQuoteUtils.getStringConnect();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ public abstract class AbstractRepositoryNodeRepositorySettingTester implements I
|
||||
if (contentType.equals(getType())) {
|
||||
return true;
|
||||
}
|
||||
if (contentType.equals(ERepositoryObjectType.PROCESS_ROUTE_DESIGN)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.talend.core.runtime.process.LastGenerationInfo;
|
||||
import org.talend.core.runtime.process.TalendProcessOptionConstants;
|
||||
import org.talend.core.ui.ITestContainerProviderService;
|
||||
import org.talend.designer.maven.utils.PomUtil;
|
||||
import org.talend.designer.maven.utils.SortableDependency;
|
||||
import org.talend.designer.runprocess.IProcessor;
|
||||
import org.talend.designer.runprocess.ProcessorException;
|
||||
|
||||
@@ -62,8 +63,10 @@ public class ProcessorDependenciesManager {
|
||||
try {
|
||||
Set<ModuleNeeded> neededLibraries = new HashSet<>();
|
||||
Set<String> uniqueDependencies = new HashSet<>();
|
||||
neededLibraries.addAll(getProcessNeededModules());
|
||||
neededLibraries.addAll(getTestcaseNeededModules(property));
|
||||
Set<ModuleNeeded> jobModules = getProcessNeededModules();
|
||||
Set<ModuleNeeded> testcaseModules = getTestcaseNeededModules(property);
|
||||
neededLibraries.addAll(jobModules);
|
||||
neededLibraries.addAll(testcaseModules);
|
||||
if (!neededLibraries.isEmpty()) {
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
|
||||
ILibraryManagerService repositoryBundleService = GlobalServiceRegister.getDefault()
|
||||
@@ -72,23 +75,8 @@ public class ProcessorDependenciesManager {
|
||||
}
|
||||
}
|
||||
List neededDependencies = new ArrayList<>();
|
||||
for (ModuleNeeded module : neededLibraries) {
|
||||
final String mavenUri = module.getMavenUri();
|
||||
if (uniqueDependencies.contains(mavenUri)) {
|
||||
continue; // must be same GAV, avoid the different other attrs for modules
|
||||
}
|
||||
uniqueDependencies.add(mavenUri);
|
||||
Dependency dependency = PomUtil.createModuleDependency(mavenUri);
|
||||
if (dependency != null) {
|
||||
if (module.isExcludeDependencies()) {
|
||||
Exclusion exclusion = new Exclusion();
|
||||
exclusion.setGroupId("*"); //$NON-NLS-1$
|
||||
exclusion.setArtifactId("*"); //$NON-NLS-1$
|
||||
dependency.addExclusion(exclusion);
|
||||
}
|
||||
neededDependencies.add(dependency);
|
||||
}
|
||||
}
|
||||
neededDependencies.addAll(convertToDependency(jobModules, uniqueDependencies, false));
|
||||
neededDependencies.addAll(convertToDependency(testcaseModules, uniqueDependencies, true));
|
||||
Collections.sort(neededDependencies);
|
||||
boolean fresh = false;
|
||||
if (property != null && property.getItem() != null && processor.getProcess() instanceof IProcess2) {
|
||||
@@ -101,6 +89,30 @@ public class ProcessorDependenciesManager {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private List convertToDependency(Set<ModuleNeeded> neededLibraries, Set<String> uniqueDependencies, boolean optional) {
|
||||
List neededDependencies = new ArrayList<>();
|
||||
for (ModuleNeeded module : neededLibraries) {
|
||||
final String mavenUri = module.getMavenUri();
|
||||
if (uniqueDependencies.contains(mavenUri)) {
|
||||
continue; // must be same GAV, avoid the different other attrs for modules
|
||||
}
|
||||
uniqueDependencies.add(mavenUri);
|
||||
Dependency dependency = PomUtil.createModuleDependency(mavenUri);
|
||||
if (dependency != null) {
|
||||
((SortableDependency) dependency).setAssemblyOptional(optional);
|
||||
if (module.isExcludeDependencies()) {
|
||||
Exclusion exclusion = new Exclusion();
|
||||
exclusion.setGroupId("*"); //$NON-NLS-1$
|
||||
exclusion.setArtifactId("*"); //$NON-NLS-1$
|
||||
dependency.addExclusion(exclusion);
|
||||
}
|
||||
neededDependencies.add(dependency);
|
||||
}
|
||||
}
|
||||
return neededDependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* DOC ggu Comment method "updateDependencies". add the job Needed Libraries for current model.
|
||||
|
||||
@@ -22,8 +22,10 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -31,6 +33,7 @@ import java.util.stream.Collectors;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.versioning.ComparableVersion;
|
||||
import org.apache.maven.model.Activation;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
@@ -631,8 +634,8 @@ public class CreateMavenJobPom extends AbstractMavenProcessorPom {
|
||||
Property currentJobProperty = processor.getProperty();
|
||||
jobCoordinate.add(getJobCoordinate(currentJobProperty));
|
||||
|
||||
// children jobs
|
||||
Set<JobInfo> childrenJobInfo = !hasLoopDependency() ? processor.getBuildChildrenJobs() : Collections.emptySet();
|
||||
// children jobs without test cases
|
||||
Set<JobInfo> childrenJobInfo = !hasLoopDependency() ? processor.getBuildChildrenJobs().stream().filter(j -> !j.isTestContainer()).collect(Collectors.toSet()) : Collections.emptySet();
|
||||
childrenJobInfo.forEach(j -> jobCoordinate.add(getJobCoordinate(j.getProcessItem().getProperty())));
|
||||
|
||||
// talend libraries and codes
|
||||
@@ -642,25 +645,27 @@ public class CreateMavenJobPom extends AbstractMavenProcessorPom {
|
||||
// codes
|
||||
addCodesDependencies(dependencies);
|
||||
|
||||
// codes dependencies
|
||||
// codes dependencies (optional)
|
||||
ERepositoryObjectType.getAllTypesOfCodes().forEach(t -> dependencies.addAll(PomUtil.getCodesDependencies(t)));
|
||||
|
||||
// libraries of talend/3rd party
|
||||
Set<ModuleNeeded> modules = processor.getNeededModules(TalendProcessOptionConstants.MODULES_EXCLUDE_SHADED);
|
||||
dependencies.addAll(convertToDistinctedJobDependencies(currentJobProperty.getId(), currentJobProperty.getVersion(),
|
||||
processor.getNeededModules(TalendProcessOptionConstants.MODULES_EXCLUDE_SHADED)));
|
||||
|
||||
// missing modules from the job generation of children
|
||||
childrenJobInfo.forEach(j -> modules
|
||||
.addAll(LastGenerationInfo.getInstance().getModulesNeededWithSubjobPerJob(j.getJobId(), j.getJobVersion())));
|
||||
childrenJobInfo.forEach(j -> dependencies.addAll(convertToDistinctedJobDependencies(j.getJobId(), j.getJobVersion(),
|
||||
LastGenerationInfo.getInstance().getModulesNeededPerJob(j.getJobId(), j.getJobVersion()))));
|
||||
|
||||
// testcase modules from children job
|
||||
Set<ModuleNeeded> modules = new HashSet<>();
|
||||
// testcase modules from current job (optional)
|
||||
modules.addAll(ProcessorDependenciesManager.getTestcaseNeededModules(currentJobProperty));
|
||||
|
||||
// testcase modules from children job (optional)
|
||||
childrenJobInfo.forEach(
|
||||
j -> modules.addAll(ProcessorDependenciesManager.getTestcaseNeededModules(j.getProcessItem().getProperty())));
|
||||
|
||||
// testcase modules from current job
|
||||
modules.addAll(ProcessorDependenciesManager.getTestcaseNeededModules(currentJobProperty));
|
||||
|
||||
dependencies.addAll(
|
||||
modules.stream().filter(m -> !m.isExcluded()).map(m -> createDenpendency(m)).collect(Collectors.toSet()));
|
||||
modules.stream().filter(m -> !m.isExcluded()).map(m -> createDenpendency(m, true)).collect(Collectors.toSet()));
|
||||
|
||||
dependencies.stream().filter(d -> !MavenConstants.PACKAGING_POM.equals(d.getType())).forEach(d -> {
|
||||
String coordinate = getCoordinate(d);
|
||||
@@ -685,8 +690,12 @@ public class CreateMavenJobPom extends AbstractMavenProcessorPom {
|
||||
Iterator<String> iterator = duplicateLibs.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Set<Dependency> dupDependencies = duplicateLibs.get(iterator.next());
|
||||
if (dupDependencies.size() < 2) {
|
||||
// remove unique dependency
|
||||
if (dupDependencies.size() < 2 // remove unique dependency
|
||||
/* || dupDependencies.stream().filter(d -> !((SortableDependency) d).isAssemblyOptional()).count() == 1 */) {
|
||||
// remove when only one required dependencies, means others are from codes/testcase
|
||||
// don't do this now at least it won't have problem in studio
|
||||
// in some case, the needed jar is not in main job pom, maven will get the nearest one which could be
|
||||
// wrong
|
||||
iterator.remove();
|
||||
} else {
|
||||
// remove duplicate dependencies from 3rd party libs
|
||||
@@ -722,9 +731,46 @@ public class CreateMavenJobPom extends AbstractMavenProcessorPom {
|
||||
}
|
||||
}
|
||||
|
||||
private Dependency createDenpendency(ModuleNeeded moduleNeeded) {
|
||||
// remove duplicate job dependencies and only keep the latest one
|
||||
// keep high priority dependencies if set by tLibraryLoad
|
||||
private Set<Dependency> convertToDistinctedJobDependencies(String jobId, String jobVersion, Set<ModuleNeeded> neededModules) {
|
||||
Set<Dependency> highPriorityDependencies = LastGenerationInfo.getInstance()
|
||||
.getHighPriorityModuleNeededPerJob(jobId, jobVersion).stream().map(m -> createDenpendency(m, false))
|
||||
.collect(Collectors.toSet());
|
||||
Map<String, Dependency> highPriorityDependenciesMap = new HashMap<>();
|
||||
highPriorityDependencies.forEach(d -> highPriorityDependenciesMap.putIfAbsent(getCheckDupCoordinate(d), d));
|
||||
|
||||
Set<Dependency> jobDependencies = neededModules.stream().filter(m -> !m.isExcluded()).map(m -> createDenpendency(m, false)).collect(Collectors.toSet());
|
||||
Map<String, Set<Dependency>> jobDependenciesMap = new HashMap<>();
|
||||
jobDependencies.forEach(d -> {
|
||||
String coordinate = getCheckDupCoordinate(d);
|
||||
if (jobDependenciesMap.get(coordinate) == null) {
|
||||
jobDependenciesMap.put(coordinate, new LinkedHashSet<>());
|
||||
}
|
||||
jobDependenciesMap.get(coordinate).add(d);
|
||||
});
|
||||
|
||||
Set<Dependency> filteredDependencies = new HashSet<>();
|
||||
jobDependenciesMap.forEach((key, value) -> {
|
||||
Optional<Dependency> target = null;
|
||||
if (highPriorityDependenciesMap.containsKey(key)) {
|
||||
Dependency highPriorityDependency = highPriorityDependenciesMap.get(key);
|
||||
target = value.stream().filter(d -> getCoordinate(highPriorityDependency).equals(getCoordinate(d))).findFirst();
|
||||
} else {
|
||||
target = value.stream().sorted(
|
||||
(d1, d2) -> new ComparableVersion(d2.getVersion()).compareTo(new ComparableVersion(d1.getVersion())))
|
||||
.findFirst();
|
||||
}
|
||||
if (target.isPresent()) {
|
||||
filteredDependencies.add(target.get());
|
||||
}
|
||||
});
|
||||
|
||||
return filteredDependencies;
|
||||
}
|
||||
|
||||
private Dependency createDenpendency(ModuleNeeded moduleNeeded, boolean optional) {
|
||||
SortableDependency dependency = (SortableDependency) PomUtil.createModuleDependency(moduleNeeded.getMavenUri());
|
||||
boolean optional = (boolean) moduleNeeded.getExtraAttributes().getOrDefault(ModuleNeeded.ASSEMBLY_OPTIONAL, false);
|
||||
dependency.setAssemblyOptional(optional);
|
||||
return dependency;
|
||||
}
|
||||
@@ -734,6 +780,11 @@ public class CreateMavenJobPom extends AbstractMavenProcessorPom {
|
||||
dependency.getVersion(), dependency.getClassifier());
|
||||
}
|
||||
|
||||
private String getCheckDupCoordinate(Dependency dependency) {
|
||||
return getCoordinate(dependency.getGroupId(), dependency.getArtifactId(), dependency.getType(), null,
|
||||
dependency.getClassifier());
|
||||
}
|
||||
|
||||
protected String getJobCoordinate(Property property) {
|
||||
return getCoordinate(PomIdsHelper.getJobGroupId(property), PomIdsHelper.getJobArtifactId(property),
|
||||
MavenConstants.PACKAGING_JAR, PomIdsHelper.getJobVersion(property), null);
|
||||
@@ -755,8 +806,7 @@ public class CreateMavenJobPom extends AbstractMavenProcessorPom {
|
||||
}
|
||||
|
||||
private void addToDuplicateLibs(Map<String, Set<Dependency>> map, Dependency dependency) {
|
||||
String coordinate = getCoordinate(dependency.getGroupId(), dependency.getArtifactId(), dependency.getType(), null,
|
||||
dependency.getClassifier());
|
||||
String coordinate = getCheckDupCoordinate(dependency);
|
||||
if (!map.containsKey(coordinate)) {
|
||||
map.put(coordinate, new HashSet<>());
|
||||
}
|
||||
|
||||
@@ -98,12 +98,7 @@ public class MavenProjectUtils {
|
||||
IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getDefault()
|
||||
.getService(IRunProcessService.class);
|
||||
|
||||
if (service.isdebug()) {
|
||||
changeClasspath(monitor, project, MavenSystemFolders.ALL_DIRS_EXT);
|
||||
} else {
|
||||
|
||||
changeClasspath(monitor, project);
|
||||
}
|
||||
changeClasspath(monitor, project, MavenSystemFolders.ALL_DIRS_EXT);
|
||||
}
|
||||
|
||||
// only need this when pom has no parent.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.talend.designer.maven.utils;
|
||||
|
||||
import org.apache.maven.artifact.versioning.ComparableVersion;
|
||||
import org.apache.maven.model.Dependency;
|
||||
|
||||
public class SortableDependency extends Dependency implements Comparable<SortableDependency> {
|
||||
@@ -15,7 +16,20 @@ public class SortableDependency extends Dependency implements Comparable<Sortabl
|
||||
public int compareTo(SortableDependency o) {
|
||||
int compare = getArtifactId().compareTo(o.getArtifactId());
|
||||
if (compare == 0) {
|
||||
return getVersion().compareTo(o.getVersion());
|
||||
// FIXME according to Maven official Doc for dependencies:
|
||||
// https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
|
||||
// when pom has duplicate version of dependencies, Maven should take the first one
|
||||
// but in practice(maven 3.5.3 embedded), it always take the last one
|
||||
// we only need job dependencies in final job zip rather than testcase's
|
||||
// so we always put the latest job dependency at the bottom
|
||||
// if maven fix it in future, we need to reverse the order as well.
|
||||
if (isAssemblyOptional && !o.isAssemblyOptional) {
|
||||
return -1;
|
||||
}
|
||||
if (!isAssemblyOptional && o.isAssemblyOptional) {
|
||||
return 1;
|
||||
}
|
||||
return new ComparableVersion(getVersion()).compareTo(new ComparableVersion(o.getVersion()));
|
||||
}
|
||||
return compare;
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@
|
||||
package org.talend.librariesmanager.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -24,9 +21,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.codehaus.jackson.map.util.ISO8601Utils;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
@@ -42,7 +36,7 @@ import org.talend.core.runtime.maven.MavenArtifact;
|
||||
import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
import org.talend.librariesmanager.i18n.Messages;
|
||||
import org.talend.librariesmanager.model.service.LocalLibraryManager;
|
||||
import org.talend.librariesmanager.nexus.utils.VersionUtil;
|
||||
import org.talend.librariesmanager.nexus.utils.ShareLibrariesUtil;
|
||||
|
||||
/**
|
||||
* created by Talend on 2015年7月31日 Detailled comment
|
||||
@@ -97,7 +91,7 @@ public abstract class ShareLibrareisHelper {
|
||||
if (searchResults != null) {
|
||||
for (MavenArtifact result : searchResults) {
|
||||
checkCancel(monitor);
|
||||
putArtifactToMap(result, releaseArtifactMap, false);
|
||||
ShareLibrariesUtil.putArtifactToMap(result, releaseArtifactMap, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,7 +101,7 @@ public abstract class ShareLibrareisHelper {
|
||||
if (searchResults != null) {
|
||||
for (MavenArtifact result : searchResults) {
|
||||
checkCancel(monitor);
|
||||
putArtifactToMap(result, snapshotArtifactMap, true);
|
||||
ShareLibrariesUtil.putArtifactToMap(result, snapshotArtifactMap, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,7 +130,7 @@ public abstract class ShareLibrareisHelper {
|
||||
//
|
||||
}
|
||||
boolean isSnapshotVersion = isSnapshotVersion(artifact.getVersion());
|
||||
String key = getArtifactKey(artifact, isSnapshotVersion);
|
||||
String key = ShareLibrariesUtil.getArtifactKey(artifact, isSnapshotVersion);
|
||||
List<MavenArtifact> artifactList = null;
|
||||
if (isSnapshotVersion) {
|
||||
artifactList = snapshotArtifactMap.get(key);
|
||||
@@ -149,7 +143,8 @@ public abstract class ShareLibrareisHelper {
|
||||
}
|
||||
}
|
||||
if (artifactList != null && artifactList.size() > 0) {
|
||||
if (isSameFileWithRemote(file, artifactList, customNexusServer, customerRepHandler, isSnapshotVersion)) {
|
||||
if (ShareLibrariesUtil.isSameFileWithRemote(file, artifactList, customNexusServer, customerRepHandler,
|
||||
isSnapshotVersion)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -187,107 +182,12 @@ public abstract class ShareLibrareisHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void putArtifactToMap(MavenArtifact artifact, Map<String, List<MavenArtifact>> map, boolean isShapshot) {
|
||||
String key = getArtifactKey(artifact, isShapshot);
|
||||
List<MavenArtifact> list = map.get(key);
|
||||
if (list == null) {
|
||||
list = new ArrayList<MavenArtifact>();
|
||||
map.put(key, list);
|
||||
}
|
||||
list.add(artifact);
|
||||
}
|
||||
|
||||
private String getArtifactKey(MavenArtifact artifact, boolean isShapshot) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(artifact.getGroupId()).append("-");
|
||||
sb.append(artifact.getArtifactId()).append("-");
|
||||
String version = artifact.getVersion();
|
||||
if (isShapshot) {
|
||||
version = VersionUtil.getSNAPSHOTVersion(version);
|
||||
}
|
||||
sb.append(version);
|
||||
if (StringUtils.isNotEmpty(artifact.getClassifier())) {
|
||||
sb.append("-").append(artifact.getClassifier());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private boolean isSameFileWithRemote(File localFile, List<MavenArtifact> artifactList,
|
||||
ArtifactRepositoryBean customNexusServer, IRepositoryArtifactHandler customerRepHandler, boolean isSnapshotVersion)
|
||||
throws Exception {
|
||||
String localFileShaCode = DigestUtils.shaHex(new FileInputStream(localFile));
|
||||
String remoteSha1 = null;
|
||||
if (ArtifactRepositoryBean.NexusType.ARTIFACTORY.name().equalsIgnoreCase(customNexusServer.getType())) {
|
||||
MavenArtifact lastUpdatedArtifact = getLateUpdatedMavenArtifact(artifactList);
|
||||
if (lastUpdatedArtifact != null) {
|
||||
remoteSha1 = lastUpdatedArtifact.getSha1();
|
||||
}
|
||||
} else if (ArtifactRepositoryBean.NexusType.NEXUS_3.name().equalsIgnoreCase(customNexusServer.getType())) {
|
||||
MavenArtifact lastUpdatedArtifact = artifactList.stream().max(Comparator.comparing(e -> e.getVersion())).get();
|
||||
if (lastUpdatedArtifact != null) {
|
||||
remoteSha1 = lastUpdatedArtifact.getSha1();
|
||||
}
|
||||
} else {
|
||||
if (!isSnapshotVersion && !Boolean.getBoolean("force_libs_release_update")) {
|
||||
return true;
|
||||
}
|
||||
MavenArtifact lastUpdatedArtifact = artifactList.get(0);
|
||||
if (lastUpdatedArtifact != null) {
|
||||
remoteSha1 = customerRepHandler.resolveRemoteSha1(lastUpdatedArtifact, !isSnapshotVersion);
|
||||
}
|
||||
}
|
||||
if (StringUtils.equals(localFileShaCode, remoteSha1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private MavenArtifact getLateUpdatedMavenArtifact(List<MavenArtifact> artifactList) {
|
||||
if (artifactList.size() == 1) {
|
||||
return artifactList.get(0);
|
||||
}
|
||||
MavenArtifact latestVersion = null;
|
||||
Date lastUpdate = null;
|
||||
for (MavenArtifact art : artifactList) {
|
||||
if (latestVersion == null) {
|
||||
if (art.getLastUpdated() != null) {
|
||||
latestVersion = art;
|
||||
lastUpdate = parsetDate(art.getLastUpdated());
|
||||
}
|
||||
} else if (art.getLastUpdated() != null && lastUpdate != null) {
|
||||
Date artLastUpdate = parsetDate(art.getLastUpdated());
|
||||
if (artLastUpdate != null && lastUpdate.getTime() < artLastUpdate.getTime()) {
|
||||
latestVersion = art;
|
||||
lastUpdate = artLastUpdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (latestVersion != null) {
|
||||
return latestVersion;
|
||||
} else {
|
||||
return artifactList.get(artifactList.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private Date parsetDate(String strDate) {
|
||||
Date date = null;
|
||||
if (strDate != null) {
|
||||
try {
|
||||
date = ISO8601Utils.parse(strDate);
|
||||
} catch (Exception ex) {
|
||||
ExceptionHandler.process(ex);
|
||||
}
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
private boolean isSnapshotVersion(String version) {
|
||||
if (version != null && version.toUpperCase().endsWith(MavenUrlHelper.VERSION_SNAPSHOT)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setJobName(Job job, String jobName) {
|
||||
if (job != null) {
|
||||
job.setName(jobName);
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -84,6 +85,7 @@ import org.talend.designer.maven.utils.PomUtil;
|
||||
import org.talend.librariesmanager.maven.MavenArtifactsHandler;
|
||||
import org.talend.librariesmanager.model.ExtensionModuleManager;
|
||||
import org.talend.librariesmanager.model.ModulesNeededProvider;
|
||||
import org.talend.librariesmanager.nexus.utils.ShareLibrariesUtil;
|
||||
import org.talend.librariesmanager.prefs.LibrariesManagerUtils;
|
||||
import org.talend.osgi.hook.notification.JarMissingObservable;
|
||||
|
||||
@@ -1369,29 +1371,82 @@ public class LocalLibraryManager implements ILibraryManagerService, IChangedLibr
|
||||
}
|
||||
|
||||
// deploy needed jars for User and Exchange component providers
|
||||
Map<String, List<MavenArtifact>> snapshotArtifactMap = new HashMap<String, List<MavenArtifact>>();
|
||||
Map<String, List<MavenArtifact>> releaseArtifactMap = new HashMap<String, List<MavenArtifact>>();
|
||||
if (!needToDeploy.isEmpty()) {
|
||||
// search on nexus to avoid deploy the jar many times
|
||||
Set<File> existFiles = new HashSet<>();
|
||||
ArtifactRepositoryBean customNexusServer = TalendLibsServerManager.getInstance().getCustomNexusServer();
|
||||
IRepositoryArtifactHandler customerRepHandler = RepositoryArtifactHandlerManager
|
||||
.getRepositoryHandler(customNexusServer);
|
||||
if (customerRepHandler != null) {
|
||||
List<MavenArtifact> searchResult = new ArrayList<>();
|
||||
List<MavenArtifact> snapshotResult = new ArrayList<>();
|
||||
List<MavenArtifact> releaseResult = new ArrayList<>();
|
||||
try {
|
||||
snapshotResult = customerRepHandler.search(MavenConstants.DEFAULT_LIB_GROUP_ID, null, null, false, true);
|
||||
if (snapshotResult != null) {
|
||||
for (MavenArtifact result : snapshotResult) {
|
||||
ShareLibrariesUtil.putArtifactToMap(result, releaseArtifactMap, true);
|
||||
}
|
||||
}
|
||||
releaseResult = customerRepHandler.search(MavenConstants.DEFAULT_LIB_GROUP_ID, null, null, true, false);
|
||||
if (releaseResult != null) {
|
||||
for (MavenArtifact result : releaseResult) {
|
||||
ShareLibrariesUtil.putArtifactToMap(result, releaseArtifactMap, false);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
for(File exsitFile:needToDeploy) {
|
||||
if (customerRepHandler != null) {
|
||||
try {
|
||||
String name = exsitFile.getName();
|
||||
String mvnUrlSnapshot = MavenUrlHelper.generateMvnUrlForJarName(name, true, true);
|
||||
MavenArtifact artifactSnapshot = MavenUrlHelper.parseMvnUrl(mvnUrlSnapshot);
|
||||
String keySnapshot = ShareLibrariesUtil.getArtifactKey(artifactSnapshot, true);
|
||||
List<MavenArtifact> artifactListSnapshot = null;
|
||||
artifactListSnapshot = snapshotArtifactMap.get(keySnapshot);
|
||||
// snapshot
|
||||
if (artifactListSnapshot != null && artifactListSnapshot.size() > 0) {
|
||||
if (ShareLibrariesUtil.isSameFileWithRemote(exsitFile, artifactListSnapshot, customNexusServer,
|
||||
customerRepHandler, false)) {
|
||||
existFiles.add(exsitFile);
|
||||
}
|
||||
}
|
||||
// release
|
||||
String mvnUrlRelease = MavenUrlHelper.generateMvnUrlForJarName(name, true, false);
|
||||
MavenArtifact artifactRelease = MavenUrlHelper.parseMvnUrl(mvnUrlRelease);
|
||||
String keyRelease = ShareLibrariesUtil.getArtifactKey(artifactRelease, false);
|
||||
List<MavenArtifact> artifactListRelease = null;
|
||||
artifactListRelease = releaseArtifactMap.get(keyRelease);
|
||||
if (artifactListRelease != null && artifactListRelease.size() > 0) {
|
||||
if (ShareLibrariesUtil.isSameFileWithRemote(exsitFile, artifactListRelease, customNexusServer,
|
||||
customerRepHandler, false)) {
|
||||
existFiles.add(exsitFile);
|
||||
}
|
||||
}
|
||||
}catch(Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
needToDeploy.removeAll(existFiles);
|
||||
// check sha code to avoid same jar in diff component depoly multi times
|
||||
Map<String, File> shaMap = new HashMap<>();
|
||||
Iterator<File> it = needToDeploy.iterator();
|
||||
while (it.hasNext()) {
|
||||
try {
|
||||
searchResult = customerRepHandler.search(MavenConstants.DEFAULT_LIB_GROUP_ID, null, null, true, true);
|
||||
File dupFile = it.next();
|
||||
String localFileShaCode = DigestUtils.shaHex(new FileInputStream(dupFile));
|
||||
if (shaMap.get(localFileShaCode) == null) {
|
||||
shaMap.put(localFileShaCode, dupFile);
|
||||
} else {
|
||||
it.remove();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
for (MavenArtifact artifact : searchResult) {
|
||||
for (File file : needToDeploy) {
|
||||
if (artifact.getFileName().equals(file.getName())) {
|
||||
existFiles.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
needToDeploy.removeAll(existFiles);
|
||||
for (File file : needToDeploy) {
|
||||
try {
|
||||
// deploy as release version if can't find mvn url from index
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.librariesmanager.nexus.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.codehaus.jackson.map.util.ISO8601Utils;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.core.nexus.ArtifactRepositoryBean;
|
||||
import org.talend.core.nexus.IRepositoryArtifactHandler;
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
|
||||
public class ShareLibrariesUtil {
|
||||
|
||||
public static boolean isSameFileWithRemote(File localFile, List<MavenArtifact> artifactList,
|
||||
ArtifactRepositoryBean customNexusServer, IRepositoryArtifactHandler customerRepHandler, boolean isSnapshotVersion)
|
||||
throws Exception {
|
||||
String localFileShaCode = DigestUtils.shaHex(new FileInputStream(localFile));
|
||||
String remoteSha1 = null;
|
||||
if (ArtifactRepositoryBean.NexusType.ARTIFACTORY.name().equalsIgnoreCase(customNexusServer.getType())) {
|
||||
MavenArtifact lastUpdatedArtifact = getLateUpdatedMavenArtifact(artifactList);
|
||||
if (lastUpdatedArtifact != null) {
|
||||
remoteSha1 = lastUpdatedArtifact.getSha1();
|
||||
}
|
||||
} else if (ArtifactRepositoryBean.NexusType.NEXUS_3.name().equalsIgnoreCase(customNexusServer.getType())) {
|
||||
MavenArtifact lastUpdatedArtifact = artifactList.stream().max(Comparator.comparing(e -> e.getVersion())).get();
|
||||
if (lastUpdatedArtifact != null) {
|
||||
remoteSha1 = lastUpdatedArtifact.getSha1();
|
||||
}
|
||||
} else {
|
||||
if (!isSnapshotVersion && !Boolean.getBoolean("force_libs_release_update")) {
|
||||
return true;
|
||||
}
|
||||
MavenArtifact lastUpdatedArtifact = artifactList.get(0);
|
||||
if (lastUpdatedArtifact != null) {
|
||||
remoteSha1 = customerRepHandler.resolveRemoteSha1(lastUpdatedArtifact, !isSnapshotVersion);
|
||||
}
|
||||
}
|
||||
if (StringUtils.equals(localFileShaCode, remoteSha1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static MavenArtifact getLateUpdatedMavenArtifact(List<MavenArtifact> artifactList) {
|
||||
if (artifactList.size() == 1) {
|
||||
return artifactList.get(0);
|
||||
}
|
||||
MavenArtifact latestVersion = null;
|
||||
Date lastUpdate = null;
|
||||
for (MavenArtifact art : artifactList) {
|
||||
if (latestVersion == null) {
|
||||
if (art.getLastUpdated() != null) {
|
||||
latestVersion = art;
|
||||
lastUpdate = parsetDate(art.getLastUpdated());
|
||||
}
|
||||
} else if (art.getLastUpdated() != null && lastUpdate != null) {
|
||||
Date artLastUpdate = parsetDate(art.getLastUpdated());
|
||||
if (artLastUpdate != null && lastUpdate.getTime() < artLastUpdate.getTime()) {
|
||||
latestVersion = art;
|
||||
lastUpdate = artLastUpdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (latestVersion != null) {
|
||||
return latestVersion;
|
||||
} else {
|
||||
return artifactList.get(artifactList.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static Date parsetDate(String strDate) {
|
||||
Date date = null;
|
||||
if (strDate != null) {
|
||||
try {
|
||||
date = ISO8601Utils.parse(strDate);
|
||||
} catch (Exception ex) {
|
||||
ExceptionHandler.process(ex);
|
||||
}
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
public static void putArtifactToMap(MavenArtifact artifact, Map<String, List<MavenArtifact>> map, boolean isShapshot) {
|
||||
String key = getArtifactKey(artifact, isShapshot);
|
||||
List<MavenArtifact> list = map.get(key);
|
||||
if (list == null) {
|
||||
list = new ArrayList<MavenArtifact>();
|
||||
map.put(key, list);
|
||||
}
|
||||
list.add(artifact);
|
||||
}
|
||||
|
||||
public static String getArtifactKey(MavenArtifact artifact, boolean isShapshot) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(artifact.getGroupId()).append("-");
|
||||
sb.append(artifact.getArtifactId()).append("-");
|
||||
String version = artifact.getVersion();
|
||||
if (isShapshot) {
|
||||
version = VersionUtil.getSNAPSHOTVersion(version);
|
||||
}
|
||||
sb.append(version);
|
||||
if (StringUtils.isNotEmpty(artifact.getClassifier())) {
|
||||
sb.append("-").append(artifact.getClassifier());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,8 @@ public class DBConnectionFillerImpl extends MetadataFillerImpl<DatabaseConnectio
|
||||
ResultSet catalogNames = null;
|
||||
if (dbJDBCMetadata instanceof SybaseDatabaseMetaData) {
|
||||
// Whether in context mode or not, metaConnection can get the correct username always
|
||||
catalogNames = ((SybaseDatabaseMetaData) dbJDBCMetadata).getCatalogs(metaConnection.getUsername());
|
||||
String username = metaConnection == null ? dbConn.getUsername() : metaConnection.getUsername();
|
||||
catalogNames = ((SybaseDatabaseMetaData) dbJDBCMetadata).getCatalogs(username);
|
||||
} else {
|
||||
catalogNames = dbJDBCMetadata.getCatalogs();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@ package org.talend.repository.items.importexport.ui.wizard.imports.providers;
|
||||
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerSorter;
|
||||
import org.talend.commons.utils.Version;
|
||||
import org.talend.repository.items.importexport.wizard.models.FolderImportNode;
|
||||
import org.talend.repository.items.importexport.wizard.models.ImportNode;
|
||||
import org.talend.repository.items.importexport.wizard.models.ItemImportNode;
|
||||
import org.talend.repository.items.importexport.wizard.models.ProjectImportNode;
|
||||
import org.talend.repository.items.importexport.wizard.models.TypeImportNode;
|
||||
@@ -53,15 +55,33 @@ public class ImportItemsViewerSorter extends ViewerSorter {
|
||||
*/
|
||||
@Override
|
||||
public int compare(Viewer viewer, Object o1, Object o2) {
|
||||
// if (o1 instanceof TypeImportNode && o2 instanceof TypeImportNode) {
|
||||
// // maybe it's not good to use the ordinal.
|
||||
// return ((TypeImportNode) o2).getType().ordinal() - ((TypeImportNode) o1).getType().ordinal();
|
||||
// } else if (o1 instanceof TypeImportNode) {
|
||||
// return 1;
|
||||
// } else if (o2 instanceof TypeImportNode) {
|
||||
// return -1;
|
||||
//
|
||||
// }
|
||||
if(o1 instanceof ImportNode && o2 instanceof ImportNode) {
|
||||
|
||||
if(((ImportNode)o1).getItemRecord() != null && ((ImportNode)o2).getItemRecord() != null
|
||||
&& ((ImportNode)o1).getItemRecord().getProperty() != null
|
||||
&& ((ImportNode)o2).getItemRecord().getProperty() != null) {
|
||||
String label1 = ((ImportNode)o1).getItemRecord().getProperty().getLabel();
|
||||
String label2 = ((ImportNode)o2).getItemRecord().getProperty().getLabel();
|
||||
if (label1 == null) {
|
||||
return -1;
|
||||
}
|
||||
if (label2 == null) {
|
||||
return 1;
|
||||
}
|
||||
if(label1.equals(label2)) {
|
||||
String version1 = ((ImportNode)o1).getItemRecord().getProperty().getVersion();
|
||||
String version2 = ((ImportNode)o2).getItemRecord().getProperty().getVersion();
|
||||
|
||||
if (version1 == null) {
|
||||
return -1;
|
||||
}
|
||||
if (version2 == null) {
|
||||
return 1;
|
||||
}
|
||||
return new Version(version1).compareTo(new Version(version2));
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.compare(viewer, o1, o2);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.repository.utils;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.talend.core.model.properties.ItemState;
|
||||
import org.talend.core.model.properties.ProcessItem;
|
||||
import org.talend.core.model.properties.PropertiesFactory;
|
||||
import org.talend.core.model.properties.Property;
|
||||
import org.talend.core.model.repository.IRepositoryViewObject;
|
||||
import org.talend.core.model.repository.RepositoryViewObject;
|
||||
import org.talend.core.repository.utils.RepositoryNodeSortUtil;
|
||||
|
||||
/**
|
||||
* @author hwang
|
||||
*
|
||||
*/
|
||||
public class RepositoryNodeSortUtilTest {
|
||||
|
||||
@Test
|
||||
public void testGetSortVersion() {
|
||||
Property property1 = PropertiesFactory.eINSTANCE.createProperty();
|
||||
property1.setId("property1"); //$NON-NLS-1$
|
||||
property1.setVersion("2.9"); //$NON-NLS-1$
|
||||
property1.setLabel("test1");//$NON-NLS-1$
|
||||
ProcessItem item1 = PropertiesFactory.eINSTANCE.createProcessItem();
|
||||
ItemState state = PropertiesFactory.eINSTANCE.createItemState();
|
||||
state.setDeleted(false);
|
||||
item1.setState(state);
|
||||
property1.setItem(item1);
|
||||
IRepositoryViewObject object1 = new RepositoryViewObject(property1, true);
|
||||
|
||||
property1 = PropertiesFactory.eINSTANCE.createProperty();
|
||||
property1.setId("property1"); //$NON-NLS-1$
|
||||
property1.setVersion("0.3"); //$NON-NLS-1$
|
||||
property1.setLabel("test1");//$NON-NLS-1$
|
||||
item1 = PropertiesFactory.eINSTANCE.createProcessItem();
|
||||
state = PropertiesFactory.eINSTANCE.createItemState();
|
||||
state.setDeleted(false);
|
||||
item1.setState(state);
|
||||
property1.setItem(item1);
|
||||
IRepositoryViewObject object2 = new RepositoryViewObject(property1, true);
|
||||
|
||||
property1 = PropertiesFactory.eINSTANCE.createProperty();
|
||||
property1.setId("property1"); //$NON-NLS-1$
|
||||
property1.setVersion("2.11"); //$NON-NLS-1$
|
||||
property1.setLabel("test1");//$NON-NLS-1$
|
||||
item1 = PropertiesFactory.eINSTANCE.createProcessItem();
|
||||
state = PropertiesFactory.eINSTANCE.createItemState();
|
||||
state.setDeleted(false);
|
||||
item1.setState(state);
|
||||
property1.setItem(item1);
|
||||
IRepositoryViewObject object3 = new RepositoryViewObject(property1, true);
|
||||
|
||||
List<IRepositoryViewObject> temp = new ArrayList<IRepositoryViewObject>();
|
||||
RepositoryNodeSortUtil util = new RepositoryNodeSortUtil();
|
||||
|
||||
temp = new ArrayList<IRepositoryViewObject>();
|
||||
temp.add(object3);
|
||||
temp.add(object2);
|
||||
temp.add(object1);
|
||||
List<IRepositoryViewObject> result = util.getSortVersion(temp);
|
||||
assertTrue("0.3".equals(result.get(0).getVersion()));
|
||||
assertTrue("2.9".equals(result.get(1).getVersion()));
|
||||
assertTrue("2.11".equals(result.get(2).getVersion()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user