Compare commits
65 Commits
release/7.
...
bugfix/mas
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcd87908ce | ||
|
|
e8e0002aa7 | ||
|
|
a7580e0ee3 | ||
|
|
b13dc822ec | ||
|
|
82a487b9e7 | ||
|
|
16fc19571c | ||
|
|
a68463d184 | ||
|
|
d04f7db182 | ||
|
|
dd201ac7fa | ||
|
|
7ce1c256dd | ||
|
|
199f4dde6e | ||
|
|
c029f53402 | ||
|
|
8aea05339a | ||
|
|
cf19586e10 | ||
|
|
c68419a4e2 | ||
|
|
819477f327 | ||
|
|
eab0938fb0 | ||
|
|
40da0e6196 | ||
|
|
8264ddedf8 | ||
|
|
b76af1a75a | ||
|
|
eecc3eff20 | ||
|
|
b8293db502 | ||
|
|
0efb40b4d5 | ||
|
|
21f5ac7771 | ||
|
|
1449055789 | ||
|
|
d1eeeb319d | ||
|
|
62bcd2d641 | ||
|
|
dbc3b0fb17 | ||
|
|
63587e1f14 | ||
|
|
cb9206e2de | ||
|
|
9e7e9c274c | ||
|
|
9c1e780550 | ||
|
|
2f14d6f7af | ||
|
|
ced9549634 | ||
|
|
12e06dcd43 | ||
|
|
b3c658190e | ||
|
|
2a152f780c | ||
|
|
e51a1be010 | ||
|
|
28df42e0fb | ||
|
|
a196cf3209 | ||
|
|
490b9df3d8 | ||
|
|
e5c48c0472 | ||
|
|
32380af191 | ||
|
|
df577338cd | ||
|
|
a56358308e | ||
|
|
0f28377fa4 | ||
|
|
9050d9050a | ||
|
|
81ea7aa0ea | ||
|
|
009e9d0cd6 | ||
|
|
d242a0e8f7 | ||
|
|
72390d4f27 | ||
|
|
9616a5028c | ||
|
|
bbc21acd80 | ||
|
|
cfcd57c65f | ||
|
|
cf9201c9d7 | ||
|
|
00b496bfba | ||
|
|
ad39bcc1f1 | ||
|
|
cbe87f5167 | ||
|
|
9bcafa150f | ||
|
|
cc400a4d22 | ||
|
|
1b1064ff73 | ||
|
|
8ea829ee81 | ||
|
|
feb4bce9b4 | ||
|
|
2c5e127de1 | ||
|
|
dfb82eb5a7 |
@@ -9,7 +9,9 @@ ProjectPomProjectSettingPage_ConfirmTitle=Confirm
|
||||
ProjectPomProjectSettingPage_ConfirmMessage=Will apply and update for project POM with modifications immediately.
|
||||
ProjectPomProjectSettingPage_FilterPomLabel=Filter to use to generate poms:
|
||||
ProjectPomProjectSettingPage_FilterErrorMessage=Filter is invalid.
|
||||
ProjectPomProjectSettingPage.syncAllPomsButtonText=Force full re-synchronize poms
|
||||
ProjectPomProjectSettingPage.syncAllPomsButtonText=Force full re-synchronize POMs
|
||||
AbstractPersistentProjectSettingPage.syncAllPoms=Do you want to update all poms? \n This operation might take long time depends on your project size.
|
||||
MavenProjectSettingPage.filterExampleMessage=Filter examples:\nlabel=myJob \t\t\t\t=> Generate only the job named "myJob"\n!(label=myJob) \t\t\t\t=> Generate any job except the one named "myJob"\n(path=folder1/folder2) \t\t\t=> Generate any job in the folder "folder1/folder2"\n(path=folder1/folder2)or(label=myJob)\t=> Generate any job in the folder "folder1/folder2" or named "myJob"\n(label=myJob)and(version=0.2)\t\t=> Generate only the job named "myJob" with version 0.2\n!((label=myJob)and(version=0.1))\t\t=> Generate every jobs except the "myJob" version 0.1
|
||||
MavenProjectSettingPage.refModuleText=Set reference project modules in profile
|
||||
MavenProjectSettingPage.excludeDeletedItems=Exclude deleted items
|
||||
MavenProjectSettingPage.syncAllPomsWarning=Click the Force full re-synchronize POMs button to apply the new settings.
|
||||
|
||||
@@ -4,5 +4,7 @@ FolderMavenSettingPage_CreatingMavenSettingPath=Chemin :
|
||||
FolderMavenSettingPage_CreatingMavenSettingErrorTitle=Erreur
|
||||
ProjectPomProjectSettingPage_Titile=NOTE\: Les modules et les d\u00E9pendances seront conserv\u00E9s.
|
||||
ProjectPomProjectSettingPage_ConfirmTitle=Confirmer
|
||||
ProjectPomProjectSettingPage.syncAllPomsButtonText=Forcer la resynchronisation des POM
|
||||
AbstractPersistentProjectSettingPage.syncAllPoms=Mettre \u00E0 jour tous les fichiers pom ? \n Cette op\u00E9ration peut prendre du temps selon la taille de votre projet.
|
||||
MavenProjectSettingPage.refModuleText=Configurer les modules du projet de r\u00E9f\u00E9rence dans le profil
|
||||
MavenProjectSettingPage.syncAllPomsWarning=Cliquez sur le bouton Forcer la resynchronisation des POM pour appliquer les nouveaux param\u00E8tres.
|
||||
|
||||
@@ -13,3 +13,4 @@ ProjectPomProjectSettingPage.syncAllPomsButtonText=POM\u306E\u5168\u518D\u540C\u
|
||||
AbstractPersistentProjectSettingPage.syncAllPoms=\u3059\u3079\u3066\u306EPOM\u3092\u66F4\u65B0\u3057\u307E\u3059\u304B? \\n \u3053\u306E\u64CD\u4F5C\u306F\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30B5\u30A4\u30BA\u306B\u3088\u3063\u3066\u306F\u6642\u9593\u304C\u304B\u304B\u308B\u5834\u5408\u304C\u3042\u308A\u307E\u3059\u3002
|
||||
MavenProjectSettingPage.filterExampleMessage=\u30D5\u30A3\u30EB\u30BF\u30FC\u306E\u4F8B:\\nlabel=myJob \\t\\t\\t\\t=> \"myJob\"\u3068\u3044\u3046\u540D\u524D\u306E\u30B8\u30E7\u30D6\u306E\u307F\u3092\u751F\u6210\\n!(label=myJob) \\t\\t\\t\\t=> \"myJob\"\u3068\u3044\u3046\u540D\u524D\u306E\u30B8\u30E7\u30D6\u3092\u9664\u304D\u3001\u3042\u3089\u3086\u308B\u30B8\u30E7\u30D6\u3092\u751F\u6210\\n(path=folder1/folder2) \\t\\t\\t=> \u30D5\u30A9\u30EB\u30C0\u30FC\"folder1/folder2\"\u5185\u306B\u4EFB\u610F\u306E\u30B8\u30E7\u30D6\u3092\u751F\u6210\\n(path=folder1/folder2)or(label=myJob)\\t=> \u30D5\u30A9\u30EB\u30C0\u30FC\"folder1/folder2\"\u5185\u306B\u4EFB\u610F\u306E\u30B8\u30E7\u30D6\u3092\u3001\u307E\u305F\u306F\"myJob\"\u3068\u3044\u3046\u540D\u524D\u306E\u30B8\u30E7\u30D6\u3092\u751F\u6210\\n(label=myJob)and(version=0.2)\\t\\t=> \u30D0\u30FC\u30B8\u30E7\u30F30.2\u3067\"myJob\"\u3068\u3044\u3046\u540D\u524D\u306E\u30B8\u30E7\u30D6\u306E\u307F\u3092\u751F\u6210\\n!((label=myJob)and(version=0.1))\\t\\t=> \"myJob\"\u30D0\u30FC\u30B8\u30E7\u30F30.1\u3092\u9664\u304D\u3001\u3059\u3079\u3066\u306E\u30B8\u30E7\u30D6\u3092\u751F\u6210
|
||||
MavenProjectSettingPage.refModuleText=\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB\u3067\u53C2\u7167\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30E2\u30B8\u30E5\u30FC\u30EB\u3092\u8A2D\u5B9A
|
||||
MavenProjectSettingPage.syncAllPomsWarning=[POM\u306E\u5168\u518D\u540C\u671F\u3092\u5F37\u5236]\u30DC\u30BF\u30F3\u3092\u30AF\u30EA\u30C3\u30AF\u3057\u3001\u65B0\u3057\u3044\u8A2D\u5B9A\u3092\u9069\u7528\u3057\u307E\u3059\u3002
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
<plugin id="org.talend.libraries.jdbc.ingres" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin id="org.talend.libraries.jdbc.mysql" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin id="org.talend.libraries.jdbc.paraccel" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin id="org.talend.libraries.jdbc.postgresql" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin id="org.talend.libraries.jdbc.sqlite3" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin id="org.talend.libraries.jdbc.teradata" download-size="0" install-size="0" version="0.0.0"/>
|
||||
</feature>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<import plugin="com.thoughtworks.paranamer" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="jackson-core-asl" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="jackson-mapper-asl" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.commons.codec" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.commons.codec" version="1.14.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.commons.compress" version="1.10.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.commons.lang" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.commons.lang3" version="0.0.0" match="greaterOrEqual"/>
|
||||
@@ -25,5 +25,6 @@
|
||||
<plugin id="org.talend.daikon" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
<plugin id="org.talend.daikon.exception" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
<plugin id="org.talend.daikon.crypto.utils" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
<plugin id="org.talend.studio.studio-utils" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
<plugin id="org.talend.utils" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
</feature>
|
||||
|
||||
|
Before Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.4 KiB |
@@ -198,7 +198,7 @@ public enum ECoreImage implements IImage {
|
||||
TRIANGLE("/icons1/triangle.gif"), // triangle.gif //$NON-NLS-1$
|
||||
COMPARE("/icons1/compare.gif"), //$NON-NLS-1$
|
||||
EXCHNAGETAB("/icons/exchangeTab.jpg"), //$NON-NLS-1$
|
||||
EXCHNAGEIMAGEMISSING("/icons/component_missing.gif"), //$NON-NLS-1$
|
||||
EXCHNAGEIMAGEMISSING("/icons/component_missing.png"), //$NON-NLS-1$
|
||||
STATUS_OK("/icons/ok.png"), //$NON-NLS-1$
|
||||
MRGREEBAR("/icons1/mrGreeBar.gif"), //$NON-NLS-1$
|
||||
MRMAP("/icons1/map.gif"), //$NON-NLS-1$
|
||||
|
||||
@@ -125,7 +125,7 @@ public enum EImage implements IImage {
|
||||
OPEN_IN_BROWSER("/icons/open.gif"), //$NON-NLS-1$
|
||||
DOWNLOAD_MODULE("/icons/download.gif"), //$NON-NLS-1$
|
||||
|
||||
COMPONENT_MISSING("/icons/component_missing.gif"), //$NON-NLS-1$
|
||||
COMPONENT_MISSING("/icons/component_missing.png"), //$NON-NLS-1$
|
||||
|
||||
FILTER_DEACTIVED_ICON("/icons/filter_deactivated.png"), //$NON-NLS-1$
|
||||
FILTER_ACTIVED_ICON("/icons/filter_activated.png"), //$NON-NLS-1$
|
||||
|
||||
@@ -16,7 +16,8 @@ Require-Bundle: org.apache.log4j;visibility:=reexport,
|
||||
org.talend.utils,
|
||||
org.eclipse.core.net,
|
||||
org.eclipse.m2e.core,
|
||||
org.eclipse.m2e.maven.runtime
|
||||
org.eclipse.m2e.maven.runtime,
|
||||
org.eclipse.core.resources
|
||||
Export-Package: org.talend.commons,
|
||||
org.talend.commons.exception,
|
||||
org.talend.commons.i18n,
|
||||
|
||||
@@ -1,431 +0,0 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// 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.commons.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.talend.commons.i18n.internal.Messages;
|
||||
|
||||
/**
|
||||
*
|
||||
* Utility class for strings. <br/>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
public class StringUtils {
|
||||
|
||||
public static String repeat(String str, int repeat) {
|
||||
return org.apache.commons.lang.StringUtils.repeat(str, repeat);
|
||||
}
|
||||
|
||||
public static String join(Object[] array, String separator) {
|
||||
return org.apache.commons.lang.StringUtils.join(array, separator);
|
||||
}
|
||||
|
||||
public static String[] split(String string, char separator) {
|
||||
return org.apache.commons.lang.StringUtils.split(string, separator);
|
||||
}
|
||||
|
||||
public static String replace(String text, String repl, String with) {
|
||||
return org.apache.commons.lang.StringUtils.replace(text, repl, with);
|
||||
}
|
||||
|
||||
public static List<String> splitAsList(String string, char separator) {
|
||||
String[] strings = org.apache.commons.lang.StringUtils.split(string, separator);
|
||||
return Arrays.asList(strings);
|
||||
}
|
||||
|
||||
public static String capitalize(String str) {
|
||||
return org.apache.commons.lang.StringUtils.capitalize(str);
|
||||
}
|
||||
|
||||
public static String getMysqlProtectedColumnName(String colname) {
|
||||
return "`" + colname + "`"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public static String getPostgresqlProtectedColumnName(String colname) {
|
||||
return "\\\"" + colname + "\\\""; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract string between the first delimiter and the second delimiter.
|
||||
*
|
||||
* @param text
|
||||
* @param delimiter
|
||||
* @return
|
||||
*/
|
||||
public static String extractFirstDelimitedString(String text, String delimiter) {
|
||||
|
||||
String returned = ""; //$NON-NLS-1$
|
||||
|
||||
int start = text.indexOf(delimiter, 0);
|
||||
|
||||
if (start != -1) {
|
||||
|
||||
int end = text.indexOf(delimiter, start + 1);
|
||||
|
||||
if (end != -1) {
|
||||
returned = text.substring(start + 1, end);
|
||||
}
|
||||
}
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
public static String protectMetachar(String input) {
|
||||
|
||||
input = replace(input, "\\", "\\\\\\\\"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = replace(input, "+", "\\\\+"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = replace(input, ".", "\\\\."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = replace(input, "[", "\\\\["); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = replace(input, "]", "\\]"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = replace(input, "(", "\\\\("); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = replace(input, ")", "\\\\)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = replace(input, "^", "\\\\^"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = replace(input, "$", "\\\\$"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
public static String removeSpecialCharsForPackage(String input) {
|
||||
input = input.replaceAll(" ", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = input.replaceAll("/", "."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = input.replaceAll("&", "and"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = input.replaceAll("<", "lt"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = input.replaceAll(">", "gt"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = input.replaceAll("'", "apos"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = input.replaceAll("\"", "quot"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = input.replaceAll("\\(", "_"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
input = input.replaceAll("\\)", "_"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return input;
|
||||
}
|
||||
|
||||
public static String loadConvert(String inputStr, String language) {
|
||||
if (inputStr == null) {
|
||||
return null;
|
||||
}
|
||||
char[] inputChars = new char[inputStr.length()];
|
||||
inputStr.getChars(0, inputStr.length(), inputChars, 0);
|
||||
String loadConvert = null;
|
||||
if (language.equalsIgnoreCase("perl")) { //$NON-NLS-1$
|
||||
loadConvert = loadConvert(inputChars, 0, inputStr.length(), new char[inputStr.length()], 'x');
|
||||
} else {
|
||||
loadConvert = loadConvert(inputChars, 0, inputStr.length(), new char[inputStr.length()], 'u');
|
||||
}
|
||||
return loadConvert;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts encoded \uxxxx to unicode chars and changes special saved chars to their original forms. it can deal
|
||||
* with the unicode encode character and the octal encode character, for example: String s =
|
||||
* "\\u8C2D\\u5148\\u94FE\0022\22\022"; it is very useful in GUI, such as Text.getText(), and will to keep the input
|
||||
* string like: \22; it can support the perl String like this: \\x2\\x22
|
||||
*/
|
||||
private static String loadConvert(char[] in, int off, int len, char[] convtBuf, char preHex) {
|
||||
boolean limitLengthForHex = false;
|
||||
int limitLength = 0;
|
||||
if (preHex == 'u') {
|
||||
limitLengthForHex = true; // in java, it must be \\uxxxx
|
||||
|
||||
limitLength = 4;
|
||||
|
||||
} else if (preHex == 'x') {
|
||||
|
||||
limitLengthForHex = false; // in perl, it can like this \\xhh
|
||||
limitLength = 2;
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException(Messages.getString("StringUtils.IllegalArgument0")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
if (convtBuf.length < len) {
|
||||
int newLen = len * 2;
|
||||
if (newLen < 0) {
|
||||
newLen = Integer.MAX_VALUE;
|
||||
}
|
||||
convtBuf = new char[newLen];
|
||||
}
|
||||
char aChar;
|
||||
char[] out = convtBuf;
|
||||
int outLen = 0;
|
||||
int end = off + len;
|
||||
|
||||
while (off < end) {
|
||||
aChar = in[off++];
|
||||
if (aChar == '\\') {
|
||||
if (off < len
|
||||
&& (in[off] == preHex || in[off] == 't' || in[off] == 'r' || in[off] == 'n' || in[off] == 'f' || Character
|
||||
.isDigit(in[off]))) {
|
||||
aChar = in[off++];
|
||||
}
|
||||
if (aChar == preHex) {
|
||||
// Read the xxxx
|
||||
int value = 0;
|
||||
for (int i = 0; i < limitLength; i++) {
|
||||
|
||||
if (off == len) {
|
||||
if (limitLengthForHex) {
|
||||
throw new IllegalArgumentException(Messages.getString("StringUtils.IllegalArgument1")); //$NON-NLS-1$
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (limitLengthForHex) {
|
||||
aChar = in[off++];
|
||||
} else if (Character.isDigit(in[off])) {
|
||||
aChar = in[off++];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (aChar) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
value = (value << 4) + aChar - '0';
|
||||
break;
|
||||
case 'a':
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'd':
|
||||
case 'e':
|
||||
case 'f':
|
||||
value = (value << 4) + 10 + aChar - 'a';
|
||||
break;
|
||||
case 'A':
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
case 'E':
|
||||
case 'F':
|
||||
value = (value << 4) + 10 + aChar - 'A';
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(Messages.getString("StringUtils.IllegalArgument2")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
out[outLen++] = (char) value;
|
||||
} else {
|
||||
if (aChar == 't') {
|
||||
aChar = '\t';
|
||||
} else if (aChar == 'r') {
|
||||
aChar = '\r';
|
||||
} else if (aChar == 'n') {
|
||||
aChar = '\n';
|
||||
} else if (aChar == 'f') {
|
||||
aChar = '\f';
|
||||
} else if (Character.isDigit(aChar)) {
|
||||
|
||||
int value = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
switch (aChar) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
value = (value << 3) + aChar - '0';
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(Messages.getString("StringUtils.IllegalArgument3")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
if (off < len && Character.isDigit(in[off])) {
|
||||
aChar = in[off++];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
aChar = (char) value;
|
||||
|
||||
}
|
||||
out[outLen++] = aChar;
|
||||
}
|
||||
} else {
|
||||
out[outLen++] = aChar;
|
||||
}
|
||||
}
|
||||
return new String(out, 0, outLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* The same as routines.system.StringUtils.escapeChar(...).
|
||||
*
|
||||
* make \n to \\n. It will process these chars: \n, \r, \t, \f, \\, \", \', \b
|
||||
*
|
||||
*/
|
||||
public static String escapeChar(String s) {
|
||||
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int length = s.length();
|
||||
StringBuffer sb = new StringBuffer(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
||||
char c = s.charAt(i);
|
||||
|
||||
switch (c) {
|
||||
case '\n':
|
||||
sb.append("\\").append('n'); //$NON-NLS-1$
|
||||
break;
|
||||
case '\r':
|
||||
sb.append("\\").append('r'); //$NON-NLS-1$
|
||||
break;
|
||||
case '\t':
|
||||
sb.append("\\").append('t'); //$NON-NLS-1$
|
||||
break;
|
||||
case '\f':
|
||||
sb.append("\\").append('f'); //$NON-NLS-1$
|
||||
break;
|
||||
case '\b':
|
||||
sb.append("\\").append('b'); //$NON-NLS-1$
|
||||
break;
|
||||
case '\"':
|
||||
sb.append("\\").append('\"'); //$NON-NLS-1$
|
||||
break;
|
||||
case '\'':
|
||||
sb.append("\\").append('\''); //$NON-NLS-1$
|
||||
break;
|
||||
default:
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String subString(String str, int len) {
|
||||
if (len < 0) {
|
||||
return str;
|
||||
}
|
||||
if ("".equals(str) || str == null) {
|
||||
return null;
|
||||
} else if (str.length() <= len) {
|
||||
return str;
|
||||
} else {
|
||||
return str.substring(0, len);
|
||||
}
|
||||
}
|
||||
|
||||
private static final String OPEN_BRACE = "{";
|
||||
|
||||
private static final String CLOSE_BRACE = "}";
|
||||
|
||||
/**
|
||||
* Replace MessageFormat.format(..) because MessageFormat does'nt support single quote correctly This method replace
|
||||
* in the text all the patterns {0}, {1}, etc.. by all values in arguments array One or more values can be null, no
|
||||
* exception is thrown if a value is null.
|
||||
*
|
||||
* @param pattern
|
||||
* @param arguments
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
public static String replacePrms(String text, Object... arguments) {
|
||||
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
text = replace(text, OPEN_BRACE + i + CLOSE_BRACE, String.valueOf(arguments[i]));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static final StringDigitComparator STR_DIGIT_COMPARATOR = new StringDigitComparator();
|
||||
|
||||
static class StringDigitComparator implements Comparator<String> {
|
||||
|
||||
final Pattern DIGIT_PATTERN = Pattern.compile("^(\\d+)"); //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public int compare(String s1, String s2) {
|
||||
return compare(s1, s2, true);
|
||||
}
|
||||
|
||||
public int compare(String s1, String s2, boolean ignoreCase) {
|
||||
int n1 = s1.length(), n2 = s2.length();
|
||||
for (int i1 = 0, i2 = 0; i1 < n1 && i2 < n2; i1++, i2++) {
|
||||
char c1 = s1.charAt(i1);
|
||||
char c2 = s2.charAt(i2);
|
||||
// check the digit, all start by digit
|
||||
if (Character.isDigit(c1) && Character.isDigit(c2)) {
|
||||
// get the digit
|
||||
String tmp1 = s1.substring(i1);
|
||||
String tmp2 = s2.substring(i2);
|
||||
Matcher matcher1 = DIGIT_PATTERN.matcher(tmp1);
|
||||
Matcher matcher2 = DIGIT_PATTERN.matcher(tmp2);
|
||||
if (matcher1.find() && matcher2.find()) {
|
||||
String digit1 = matcher1.group(1);
|
||||
String digit2 = matcher2.group(1);
|
||||
int d1 = Integer.parseInt(digit1);
|
||||
int d2 = Integer.parseInt(digit2);
|
||||
if (d1 == d2) { // same digit, check the left strings
|
||||
String left1 = tmp1.substring(digit1.length());
|
||||
String left2 = tmp2.substring(digit2.length());
|
||||
return compare(left1, left2, ignoreCase);
|
||||
} else {
|
||||
return d1 - d2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (c1 != c2) {
|
||||
if (ignoreCase) {
|
||||
c1 = Character.toUpperCase(c1);
|
||||
c2 = Character.toUpperCase(c2);
|
||||
if (c1 != c2) {
|
||||
c1 = Character.toLowerCase(c1);
|
||||
c2 = Character.toLowerCase(c2);
|
||||
if (c1 != c2) {
|
||||
return c1 - c2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return c1 - c2;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return n1 - n2;
|
||||
}
|
||||
};
|
||||
|
||||
public static int compareStringDigit(String s1, String s2, boolean ignoreCase) {
|
||||
return STR_DIGIT_COMPARATOR.compare(s1, s2, ignoreCase);
|
||||
}
|
||||
|
||||
public static int compareStringDigit(String s1, String s2) {
|
||||
return STR_DIGIT_COMPARATOR.compare(s1, s2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,11 +49,17 @@ public class EclipseCommandLine {
|
||||
*/
|
||||
static public final String TALEND_PROJECT_TYPE_COMMAND = "-talendProjectType"; //$NON-NLS-1$
|
||||
|
||||
static public final String TALEND_LICENCE_PATH = "talend.licence.path"; //$NON-NLS-1$
|
||||
|
||||
static public final String ARG_TALEND_LICENCE_PATH = "-" + TALEND_LICENCE_PATH; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* for relaunch of the plugins when relaunching the Studio
|
||||
*/
|
||||
static public final String TALEND_RELOAD_COMMAND = "-talendReload"; //$NON-NLS-1$
|
||||
|
||||
static public final String LOGIN_ONLINE_UPDATE = "--loginOnlineUpdate";
|
||||
|
||||
static public final String ARG_TALEND_BUNDLES_CLEANED = "-talend.studio.bundles.cleaned"; //$NON-NLS-1$
|
||||
|
||||
static public final String PROP_TALEND_BUNDLES_DO_CLEAN = "-talend.studio.bundles.doclean"; //$NON-NLS-1$
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package org.talend.commons.utils.threading.lockerbykey;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
*
|
||||
* CustomReentrantLock class.
|
||||
*
|
||||
* @see java.util.concurrent.locks.ReentrantLock
|
||||
*/
|
||||
public class CustomReentrantLock extends ReentrantLock {
|
||||
|
||||
private static final long serialVersionUID = 3730576759454516775L;
|
||||
|
||||
public CustomReentrantLock() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CustomReentrantLock(boolean fair) {
|
||||
super(fair);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.locks.ReentrantLock#getQueuedThreads()
|
||||
*/
|
||||
@Override
|
||||
public Collection<Thread> getQueuedThreads() {
|
||||
return super.getQueuedThreads();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.util.concurrent.locks.ReentrantLock#getOwner()
|
||||
*/
|
||||
@Override
|
||||
public Thread getOwner() {
|
||||
return super.getOwner();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// 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.commons.utils.threading.lockerbykey;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* DOC amaumont class global comment. Detailled comment
|
||||
*/
|
||||
public interface ILockerByKey<KP> {
|
||||
|
||||
public abstract int getCleanPeriod();
|
||||
|
||||
public abstract void shutdownNow();
|
||||
|
||||
public abstract void shutdown();
|
||||
|
||||
public abstract LockerValue<KP> getLockerValue(KP key);
|
||||
|
||||
public abstract boolean unlock(KP key);
|
||||
|
||||
public abstract boolean tryLock(KP key, long timeout, TimeUnit unit) throws InterruptedException;
|
||||
|
||||
public abstract boolean tryLock(KP key, long timeout) throws InterruptedException;
|
||||
|
||||
public abstract boolean tryLock(KP key);
|
||||
|
||||
public abstract void lockInterruptibly(KP key) throws InterruptedException;
|
||||
|
||||
public abstract boolean isLocked(KP key);
|
||||
|
||||
public abstract void clean();
|
||||
|
||||
public abstract List<LockerValue<KP>> getSuspectLocks(long timeDetectionLimitMs);
|
||||
|
||||
public abstract void setDetectSuspectLocks(boolean detectSuspectLocks);
|
||||
|
||||
public abstract boolean isDetectSuspectLocks();
|
||||
|
||||
}
|
||||
@@ -1,617 +0,0 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// 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.commons.utils.threading.lockerbykey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.talend.commons.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* This class is useful to lock some part of code from the provided key.
|
||||
*
|
||||
* This class has the same behaviour that <code>java.util.concurrent.locks.ReentrantLock</code> except additionally it
|
||||
* expect keys to lock the parts of code.
|
||||
*
|
||||
* It uses internally a <code>java.util.concurrent.ConcurrentHashMap</code> to store locks from keys <code>KP</code> and
|
||||
* the <code>java.util.concurrent.locks.ReentrantLock</code> as properties of a value wrapper. <br/>
|
||||
*
|
||||
* @see java.util.concurrent.locks.ReentrantLock
|
||||
*
|
||||
* @param <KP> type of the key
|
||||
*/
|
||||
public class LockerByKey<KP> implements ILockerByKey<KP> {
|
||||
|
||||
private static Logger log = Logger.getLogger(LockerByKey.class);
|
||||
|
||||
private ConcurrentHashMap<InternalKeyLock<KP>, LockerValue<KP>> mapKeyLockToValueLock = new ConcurrentHashMap<InternalKeyLock<KP>, LockerValue<KP>>();
|
||||
|
||||
private final Object lockAllOperations = new Object();
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
private AtomicInteger runningOperations = new AtomicInteger();
|
||||
|
||||
private final static int DEFAULT_CLEAN_PERIOD = 500;
|
||||
|
||||
private final static boolean DEFAULT_FAIR = true;
|
||||
|
||||
private int cleanPeriod;
|
||||
|
||||
private boolean fair;
|
||||
|
||||
private volatile boolean blockAllOperations;
|
||||
|
||||
private volatile boolean shuttingDown;
|
||||
|
||||
private volatile boolean stopped;
|
||||
|
||||
private static boolean detectSuspectLocksStatic = false;
|
||||
|
||||
private boolean detectSuspectLocks = false;
|
||||
|
||||
private boolean forceShutdown;
|
||||
|
||||
static {
|
||||
String optionKey = "detectSuspectLocks";
|
||||
String detectSuspectLocksStr = System.getProperty(optionKey);
|
||||
if (detectSuspectLocksStr != null && detectSuspectLocksStr.length() > 0) {
|
||||
detectSuspectLocksStatic = Boolean.parseBoolean(detectSuspectLocksStr);
|
||||
}
|
||||
if (detectSuspectLocksStatic) {
|
||||
log.info("System property \"" + optionKey + "\"=" + detectSuspectLocksStatic);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* LockerByKey constructor.
|
||||
*/
|
||||
public LockerByKey() {
|
||||
this(DEFAULT_FAIR, DEFAULT_CLEAN_PERIOD);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor LockerByKey.
|
||||
*
|
||||
* @param fair {@code true} if this lock should use a fair ordering policy
|
||||
*/
|
||||
public LockerByKey(boolean fair) {
|
||||
this(fair, DEFAULT_CLEAN_PERIOD);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor LockerByKey.
|
||||
*
|
||||
* @param cleanPeriod in number of operations, it means that an automatic clean will be done for each
|
||||
* <code>cleanPeriod</code> number of unlock operation.
|
||||
*/
|
||||
public LockerByKey(int cleanPeriod) {
|
||||
this(DEFAULT_FAIR, cleanPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor LockerByKey.
|
||||
*
|
||||
* @param fair {@code true} if this lock should use a fair ordering policy
|
||||
* @param cleanPeriod in number of operations, it means that an automatic clean will be done after each
|
||||
* <code>cleanPeriod</code> number of unlock operation.
|
||||
*/
|
||||
public LockerByKey(boolean fair, int cleanPeriod) {
|
||||
super();
|
||||
this.fair = fair;
|
||||
if (cleanPeriod <= 0) {
|
||||
throw new IllegalArgumentException("The cleanPeriod value has to be greater than 0");
|
||||
}
|
||||
this.cleanPeriod = cleanPeriod;
|
||||
this.detectSuspectLocks = detectSuspectLocksStatic;
|
||||
if (this.detectSuspectLocks) {
|
||||
launchThreadDebugger();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor LockerByKey.
|
||||
*
|
||||
* @param fair {@code true} if this lock should use a fair ordering policy
|
||||
* @param cleanDisabled true to disable the clean completely <code>cleanPeriod</code> number of unlock operation.
|
||||
*/
|
||||
protected LockerByKey(boolean fair, boolean cleanDisabled) {
|
||||
super();
|
||||
this.fair = fair;
|
||||
if (cleanDisabled) {
|
||||
this.cleanPeriod = 0;
|
||||
} else {
|
||||
this.cleanPeriod = DEFAULT_CLEAN_PERIOD;
|
||||
}
|
||||
this.detectSuspectLocks = detectSuspectLocksStatic;
|
||||
if (this.detectSuspectLocks) {
|
||||
launchThreadDebugger();
|
||||
}
|
||||
}
|
||||
|
||||
private void launchThreadDebugger() {
|
||||
new Thread(this.getClass().getSimpleName() + "-ThreadDebugger-" + this.hashCode()) {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Thread#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (!stopped && !shuttingDown) {
|
||||
try {
|
||||
Thread.sleep(30000);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
long timeDetectionLimitMs = 30000L;
|
||||
List<LockerValue<KP>> lockerValues = getSuspectLocks(timeDetectionLimitMs);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (LockerValue<KP> lockerValue : lockerValues) {
|
||||
long duration = System.currentTimeMillis() - lockerValue.getLockedTime();
|
||||
StackTraceElement[] stackTraceOfLocker = lockerValue.getStackTraceOfLocker();
|
||||
for (StackTraceElement trace : stackTraceOfLocker) {
|
||||
StackTraceElement stackTraceElement = trace;
|
||||
sb.append(stackTraceElement.toString());
|
||||
sb.append("\n");
|
||||
}
|
||||
log.warn("Suspect lock done since " + duration + " ms by: " + sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "isLocked".
|
||||
*
|
||||
* @param key
|
||||
* @return true if any thread holds this lock and false otherwise
|
||||
*
|
||||
* @see java.util.concurrent.locks.ReentrantLock#isLocked()
|
||||
*/
|
||||
@Override
|
||||
public boolean isLocked(KP key) {
|
||||
checkKey(key);
|
||||
LockerValue<KP> locker = getLockerValue(key);
|
||||
return locker != null && locker.getLock().isLocked();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Method "lockInterruptibly".
|
||||
*
|
||||
* @param key
|
||||
* @throws InterruptedException
|
||||
* @see java.util.concurrent.locks.ReentrantLock#lockInterruptibly()
|
||||
*/
|
||||
@Override
|
||||
public void lockInterruptibly(KP key) throws InterruptedException {
|
||||
checkStopped();
|
||||
checkKey(key);
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
LockerValue<KP> lockerValue = prepareInternalLock(key);
|
||||
decrementRunningOperations();
|
||||
lockerValue.getLock().lockInterruptibly();
|
||||
traceStackForDebugging(lockerValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "tryLock".
|
||||
*
|
||||
* @param key
|
||||
* @return {@code true} if the lock was free and was acquired by the current thread, or the lock was already held by
|
||||
* the current thread; and {@code false} otherwise
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if bean is null
|
||||
* @see java.util.concurrent.locks.ReentrantLock#tryLock()
|
||||
*/
|
||||
@Override
|
||||
public boolean tryLock(KP key) {
|
||||
if (stopped || shuttingDown) {
|
||||
return false;
|
||||
}
|
||||
checkKey(key);
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
LockerValue<KP> lockerValue = prepareInternalLock(key);
|
||||
decrementRunningOperations();
|
||||
boolean locked = lockerValue.getLock().tryLock();
|
||||
if (locked) {
|
||||
traceStackForDebugging(lockerValue);
|
||||
}
|
||||
return locked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "tryLock".
|
||||
*
|
||||
* @param key
|
||||
* @param timeout the time to wait for the lock in milliseconds
|
||||
* @return true if the lock was free and was acquired by the current thread, or the lock was already held by the
|
||||
* current thread; and false if the waiting time elapsed before the lock could be acquired
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if bean is null
|
||||
* @see java.util.concurrent.locks.ReentrantLock#tryLock(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
@Override
|
||||
public boolean tryLock(KP key, long timeout) throws InterruptedException {
|
||||
return tryLock(key, timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "tryLock".
|
||||
*
|
||||
* @param key
|
||||
* @param timeout the time to wait for the lock
|
||||
* @param unit the time unit of the timeout argument
|
||||
* @return true if the lock was free and was acquired by the current thread, or the lock was already held by the
|
||||
* current thread; and false if the waiting time elapsed before the lock could be acquired
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if bean is null
|
||||
*
|
||||
* @see java.util.concurrent.locks.ReentrantLock#tryLock(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
@Override
|
||||
public boolean tryLock(KP key, long timeout, TimeUnit unit) throws InterruptedException {
|
||||
checkStopped();
|
||||
checkKey(key);
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
LockerValue<KP> lockerValue = prepareInternalLock(key);
|
||||
decrementRunningOperations();
|
||||
interruptIfStopping();
|
||||
boolean locked = lockerValue.getLock().tryLock(timeout, unit);
|
||||
if (locked) {
|
||||
traceStackForDebugging(lockerValue);
|
||||
}
|
||||
return locked;
|
||||
}
|
||||
|
||||
private LockerValue<KP> prepareInternalLock(KP key) {
|
||||
InternalKeyLock<KP> internalKeyLock = new InternalKeyLock<KP>(key);
|
||||
LockerValue<KP> lockerValue = new LockerValue<KP>(key, fair);
|
||||
LockerValue<KP> previousLockerValue = null;
|
||||
previousLockerValue = mapKeyLockToValueLock.putIfAbsent(internalKeyLock, lockerValue);
|
||||
if (previousLockerValue != null) {
|
||||
lockerValue = previousLockerValue;
|
||||
}
|
||||
return lockerValue;
|
||||
}
|
||||
|
||||
private void interruptIfStopping() throws InterruptedException {
|
||||
if (shuttingDown) {
|
||||
throw new InterruptedException("This LockerByKey is shutting down...");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "unlock". Unlock the operations with the provided key.
|
||||
*
|
||||
* @param key
|
||||
* @return true if the key has been found to release the lock; and false otherwise
|
||||
* @see java.util.concurrent.locks.ReentrantLock#unlock()
|
||||
*/
|
||||
@Override
|
||||
public boolean unlock(KP key) {
|
||||
checkKey(key);
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
LockerValue<KP> lockerValue = getLockerValue(key);
|
||||
boolean returnValue = false;
|
||||
if (lockerValue != null) {
|
||||
lockerValue.getLock().unlock();
|
||||
returnValue = true;
|
||||
}
|
||||
decrementRunningOperations();
|
||||
cleanAccordingOperations();
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
void traceStackForDebugging(LockerValue<KP> lockerValue) {
|
||||
if (this.detectSuspectLocks) {
|
||||
lockerValue.setStackTraceOfLocker(Thread.currentThread().getStackTrace());
|
||||
lockerValue.setLockedTime(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanAccordingOperations() {
|
||||
synchronized (lockAllOperations) {
|
||||
if (cleanPeriod > 0 && counter.incrementAndGet() % cleanPeriod == 0) {
|
||||
clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Method "clean".
|
||||
*
|
||||
* Clean the map which contains the lock wrappers.
|
||||
*
|
||||
* Removed lock wrappers are these where lock is not locked by a thread and no one thread is waiting to obtain the
|
||||
* lock.
|
||||
*
|
||||
* The default clean will do an automatic clean all 1000 unlock operation, you can disable or change this value from
|
||||
* the constructor.
|
||||
*/
|
||||
@Override
|
||||
public void clean() {
|
||||
synchronized (lockAllOperations) {
|
||||
blockAllOperations();
|
||||
if (!(forceShutdown && shuttingDown)) {
|
||||
waitForRunningOperationsEnded();
|
||||
}
|
||||
Collection<LockerValue<KP>> values = mapKeyLockToValueLock.values();
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Cleaning " + this.toString() + " : " + values.size() + " keys/values ...");
|
||||
}
|
||||
InternalKeyLock<KP> internalKeyLock = new InternalKeyLock<KP>();
|
||||
for (LockerValue<KP> lockerValue : values) {
|
||||
ReentrantLock lock = lockerValue.getLock();
|
||||
LockerValueHandler handler = lockerValue.getHandler();
|
||||
if (!lock.hasQueuedThreads() && !lock.isLocked() && handler == null) {
|
||||
internalKeyLock.setKey(lockerValue.getKey());
|
||||
mapKeyLockToValueLock.remove(internalKeyLock);
|
||||
}
|
||||
}
|
||||
resumeAllOperations();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStopped() {
|
||||
if (stopped || shuttingDown) {
|
||||
throw new IllegalStateException("This locker is already stopped or is shutting down !");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "check". Check if the key is not null.
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
private void checkKey(KP key) {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("key can't be null"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private void waitForRunningOperationsEnded() {
|
||||
while (runningOperations.get() > 0) {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resumeAllOperations() {
|
||||
this.blockAllOperations = false;
|
||||
lockAllOperations.notifyAll();
|
||||
}
|
||||
|
||||
private void blockAllOperations() {
|
||||
this.blockAllOperations = true;
|
||||
}
|
||||
|
||||
private void blockOperationIfRequired() {
|
||||
if (blockAllOperations) {
|
||||
synchronized (lockAllOperations) {
|
||||
if (blockAllOperations) {
|
||||
try {
|
||||
lockAllOperations.wait();
|
||||
} catch (InterruptedException e) {
|
||||
log.warn(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void decrementRunningOperations() {
|
||||
runningOperations.decrementAndGet();
|
||||
}
|
||||
|
||||
private void incrementRunningOperations() {
|
||||
runningOperations.incrementAndGet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get locker.
|
||||
*
|
||||
* @param bean
|
||||
* @return locker value.
|
||||
*/
|
||||
@Override
|
||||
public LockerValue<KP> getLockerValue(KP key) {
|
||||
checkKey(key);
|
||||
InternalKeyLock<KP> internalKeyLock = new InternalKeyLock<KP>(key);
|
||||
return mapKeyLockToValueLock.get(internalKeyLock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void shutdownNow() {
|
||||
forceShutdown = true;
|
||||
shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void shutdown() {
|
||||
shuttingDown = true;
|
||||
blockAllOperations();
|
||||
if (!forceShutdown) {
|
||||
waitForRunningOperationsEnded();
|
||||
}
|
||||
Collection<LockerValue<KP>> values = mapKeyLockToValueLock.values();
|
||||
for (LockerValue<KP> lockerValue : values) {
|
||||
Collection<Thread> queuedThreads = lockerValue.getLock().getQueuedThreads();
|
||||
for (Thread thread : queuedThreads) {
|
||||
thread.interrupt();
|
||||
}
|
||||
}
|
||||
clean();
|
||||
stopped = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LockerByKey:" + super.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for cleanFrequency.
|
||||
*
|
||||
* @return the cleanFrequency
|
||||
*/
|
||||
@Override
|
||||
public int getCleanPeriod() {
|
||||
return cleanPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for detectSuspectLocks.
|
||||
*
|
||||
* @return the detectSuspectLocks
|
||||
*/
|
||||
@Override
|
||||
public boolean isDetectSuspectLocks() {
|
||||
return this.detectSuspectLocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the detectSuspectLocks.
|
||||
*
|
||||
* @param detectSuspectLocks the detectSuspectLocks to set
|
||||
*/
|
||||
@Override
|
||||
public void setDetectSuspectLocks(boolean detectSuspectLocks) {
|
||||
this.detectSuspectLocks = detectSuspectLocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LockerValue<KP>> getSuspectLocks(long timeDetectionLimitMs) {
|
||||
if (this.detectSuspectLocks) {
|
||||
Collection<LockerValue<KP>> values = mapKeyLockToValueLock.values();
|
||||
List<LockerValue<KP>> stacks = new ArrayList<LockerValue<KP>>();
|
||||
for (LockerValue<KP> lockerValue : values) {
|
||||
long lockedTime = lockerValue.getLockedTime();
|
||||
long duration = System.currentTimeMillis() - lockedTime;
|
||||
if (lockedTime > 0 && duration > timeDetectionLimitMs && lockerValue.getLock().isLocked()) {
|
||||
stacks.add(lockerValue);
|
||||
}
|
||||
}
|
||||
return stacks;
|
||||
} else {
|
||||
throw new UnsupportedOperationException(
|
||||
"You have to enable the 'detectSuspectLocks' mode by using the JVM argument -DdetectSuspectLocks=true");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* LockerByKey class.<br/>
|
||||
*
|
||||
* @param <IKP> key
|
||||
*/
|
||||
class InternalKeyLock<IKP> {
|
||||
|
||||
private IKP key;
|
||||
|
||||
public InternalKeyLock() {
|
||||
}
|
||||
|
||||
/**
|
||||
* InternalKeyLock constructor comment.
|
||||
*
|
||||
* @param key2
|
||||
*/
|
||||
public InternalKeyLock(IKP key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.key == null) ? 0 : this.key.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final InternalKeyLock other = (InternalKeyLock) obj;
|
||||
if (this.key == null) {
|
||||
if (other.key != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this.key.equals(other.key)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setKey(IKP key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return StringUtils.replacePrms(InternalKeyLock.class.getSimpleName() + ": key={0}", key); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for mapKeyLockToValueLock.
|
||||
*
|
||||
* @return the mapKeyLockToValueLock
|
||||
*/
|
||||
Map<InternalKeyLock<KP>, LockerValue<KP>> getMapKeyLockToValueLock() {
|
||||
return new HashMap<InternalKeyLock<KP>, LockerValue<KP>>(mapKeyLockToValueLock);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,669 +0,0 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// 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.commons.utils.threading.lockerbykey;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class LockerByKeyUnrestricted.
|
||||
*
|
||||
* This class has the same behaviours that {@link LockerByKey} except
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class LockerByKeyUnrestricted<KP> implements ILockerByKey<KP> {
|
||||
|
||||
private static final String NOT_ALREADY_LOCKED_MESSAGE = "Already unlocked by an other thread or never locked, ensure all the unlock() operations of this locker are called after their lock has really locked:";
|
||||
|
||||
private static Logger log = Logger.getLogger(LockerByKeyUnrestricted.class);
|
||||
|
||||
private ExecutorService threadPool;
|
||||
|
||||
private LockerByKey<KP> locker;
|
||||
|
||||
private final Object lockAllOperations = new Object();
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
private AtomicInteger runningOperations = new AtomicInteger();
|
||||
|
||||
private final static int DEFAULT_CLEAN_PERIOD = 500;
|
||||
|
||||
private final static boolean DEFAULT_FAIR = true;
|
||||
|
||||
private volatile boolean blockAllOperations;
|
||||
|
||||
private volatile boolean shuttingDown;
|
||||
|
||||
private volatile boolean stopped;
|
||||
|
||||
private int cleanPeriod;
|
||||
|
||||
/**
|
||||
* LockerByKey constructor.
|
||||
*/
|
||||
public LockerByKeyUnrestricted() {
|
||||
this(DEFAULT_FAIR, DEFAULT_CLEAN_PERIOD);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor LockerByKey.
|
||||
*
|
||||
* @param fair {@code true} if this lock should use a fair ordering policy
|
||||
*/
|
||||
public LockerByKeyUnrestricted(boolean fair) {
|
||||
this(fair, DEFAULT_CLEAN_PERIOD);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor LockerByKey.
|
||||
*
|
||||
* @param cleanPeriod in number of operations, it means that an automatic clean will be done for each
|
||||
* <code>cleanPeriod</code> number of unlock operation.
|
||||
*/
|
||||
public LockerByKeyUnrestricted(int cleanPeriod) {
|
||||
this(DEFAULT_FAIR, cleanPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor LockerByKey.
|
||||
*
|
||||
* @param fair {@code true} if this lock should use a fair ordering policy
|
||||
* @param cleanPeriod in number of operations, it means that an automatic clean will be done for each
|
||||
* <code>cleanPeriod</code> number of unlock operation.
|
||||
*/
|
||||
public LockerByKeyUnrestricted(boolean fair, int cleanPeriod) {
|
||||
super();
|
||||
if (cleanPeriod <= 0) {
|
||||
throw new IllegalArgumentException("The cleanPeriod value has to be greater than 0");
|
||||
}
|
||||
boolean cleanDisabled = true;
|
||||
this.locker = new LockerByKey<KP>(fair, cleanDisabled);
|
||||
this.threadPool = intializePool(LockerByKeyUnrestricted.class.getSimpleName());
|
||||
this.cleanPeriod = cleanPeriod;
|
||||
}
|
||||
|
||||
protected ExecutorService intializePool(final String poolName) {
|
||||
ExecutorService threadPool = Executors.newCachedThreadPool(new ThreadFactory() {
|
||||
|
||||
ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory();
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread newThread = defaultThreadFactory.newThread(r);
|
||||
newThread.setName(poolName + "_" + newThread.getName());
|
||||
return newThread;
|
||||
}
|
||||
|
||||
});
|
||||
return threadPool;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Method "lockInterruptibly".
|
||||
*
|
||||
* @param key
|
||||
* @throws InterruptedException
|
||||
* @see java.util.concurrent.locks.ReentrantLock#lockInterruptibly()
|
||||
*/
|
||||
@Override
|
||||
public void lockInterruptibly(final KP key) throws InterruptedException {
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
try {
|
||||
locker.lockInterruptibly(key);
|
||||
} finally {
|
||||
decrementRunningOperations();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Method "lockInterruptiblyUnrestricted".
|
||||
*
|
||||
* @param key
|
||||
* @throws InterruptedException
|
||||
* @see java.util.concurrent.locks.ReentrantLock#lockInterruptibly()
|
||||
*/
|
||||
public void lockInterruptiblyUnrestricted(final KP key) throws InterruptedException {
|
||||
checkStopped();
|
||||
blockOperationIfRequired();
|
||||
|
||||
LockerValue<KP> lockerValue = null;
|
||||
LockerValueHandler handler = null;
|
||||
|
||||
if (tryLockUnrestricted(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
incrementRunningOperations();
|
||||
|
||||
/* Test if already locked by the same thread */
|
||||
lockerValue = locker.getLockerValue(key);
|
||||
if (locker != null) {
|
||||
handler = lockerValue.getHandler();
|
||||
if (handler != null && Thread.currentThread() == handler.getCallerThreadLocker()) {
|
||||
decrementRunningOperations();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
final Thread threadLocker = Thread.currentThread();
|
||||
final CyclicBarrier cyclicBarrier = new CyclicBarrier(2);
|
||||
final AtomicBoolean hasError = new AtomicBoolean();
|
||||
Callable<Boolean> callable = new Callable<Boolean>() {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.util.concurrent.Callable#call()
|
||||
*/
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
try {
|
||||
locker.lockInterruptibly(key);
|
||||
} catch (Exception e) {
|
||||
hasError.set(true);
|
||||
throw e;
|
||||
} finally {
|
||||
// STEP 1
|
||||
cyclicBarrier.await();
|
||||
}
|
||||
// STEP 2
|
||||
cyclicBarrier.await();
|
||||
boolean unlocked = locker.unlock(key);
|
||||
return unlocked;
|
||||
}
|
||||
|
||||
};
|
||||
Future<Boolean> futureTask = threadPool.submit(callable);
|
||||
try {
|
||||
// STEP 1
|
||||
cyclicBarrier.await();
|
||||
} catch (BrokenBarrierException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (hasError.get()) {
|
||||
try {
|
||||
futureTask.get();
|
||||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause != null && cause instanceof InterruptedException) {
|
||||
throw (InterruptedException) cause;
|
||||
} else {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lockerValue = locker.getLockerValue(key);
|
||||
lockerValue.addHandler(new LockerValueHandler(futureTask, cyclicBarrier, threadLocker));
|
||||
} finally {
|
||||
decrementRunningOperations();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "tryLock".
|
||||
*
|
||||
* @param key
|
||||
* @return {@code true} if the lock was free and was acquired by the current thread, or the lock was already held by
|
||||
* the current thread; and {@code false} otherwise
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if bean is null
|
||||
* @see java.util.concurrent.locks.ReentrantLock#tryLock()
|
||||
*/
|
||||
@Override
|
||||
public boolean tryLock(final KP key) {
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
try {
|
||||
return locker.tryLock(key);
|
||||
} finally {
|
||||
decrementRunningOperations();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "tryLockUnrestricted".
|
||||
*
|
||||
* @param key
|
||||
* @return {@code true} if the lock was free and was acquired by the current thread, or the lock was already held by
|
||||
* the current thread; and {@code false} otherwise
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if bean is null
|
||||
* @see java.util.concurrent.locks.ReentrantLock#tryLock()
|
||||
*/
|
||||
public boolean tryLockUnrestricted(final KP key) {
|
||||
checkStopped();
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
boolean tryLockResultBoolean;
|
||||
try {
|
||||
final AtomicBoolean tryLockResult = new AtomicBoolean();
|
||||
final CyclicBarrier cyclicBarrier = new CyclicBarrier(2);
|
||||
Callable<Boolean> callable = new Callable<Boolean>() {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.util.concurrent.Callable#call()
|
||||
*/
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
boolean locked;
|
||||
try {
|
||||
locked = locker.tryLock(key);
|
||||
tryLockResult.set(locked);
|
||||
} finally {
|
||||
// STEP 1
|
||||
cyclicBarrier.await();
|
||||
}
|
||||
if (locked) {
|
||||
// STEP 2
|
||||
cyclicBarrier.await();
|
||||
return locker.unlock(key);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
Future<Boolean> futureTask = threadPool.submit(callable);
|
||||
try {
|
||||
// STEP 1
|
||||
cyclicBarrier.await();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
tryLockResultBoolean = tryLockResult.get();
|
||||
if (tryLockResultBoolean) {
|
||||
LockerValue<KP> lockerValue = locker.getLockerValue(key);
|
||||
Thread callerThreadLocker = Thread.currentThread();
|
||||
lockerValue.addHandler(new LockerValueHandler(futureTask, cyclicBarrier, callerThreadLocker));
|
||||
}
|
||||
} finally {
|
||||
decrementRunningOperations();
|
||||
}
|
||||
return tryLockResultBoolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "tryLock".
|
||||
*
|
||||
* @param key
|
||||
* @param timeout the time to wait for the lock in milliseconds
|
||||
* @return true if the lock was free and was acquired by the current thread, or the lock was already held by the
|
||||
* current thread; and false if the waiting time elapsed before the lock could be acquired
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if bean is null
|
||||
* @see java.util.concurrent.locks.ReentrantLock#tryLock(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
@Override
|
||||
public boolean tryLock(final KP key, final long timeout) throws InterruptedException {
|
||||
return locker.tryLock(key, timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "tryLockUnrestricted".
|
||||
*
|
||||
* @param key
|
||||
* @param timeout the time to wait for the lock in milliseconds
|
||||
* @return true if the lock was free and was acquired by the current thread, or the lock was already held by the
|
||||
* current thread; and false if the waiting time elapsed before the lock could be acquired
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if bean is null
|
||||
* @see java.util.concurrent.locks.ReentrantLock#tryLock(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
public boolean tryLockUnrestricted(final KP key, final long timeout) throws InterruptedException {
|
||||
return tryLockUnrestricted(key, timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "tryLock".
|
||||
*
|
||||
* @param key
|
||||
* @param timeout the time to wait for the lock
|
||||
* @param unit the time unit of the timeout argument
|
||||
* @return true if the lock was free and was acquired by the current thread, or the lock was already held by the
|
||||
* current thread; and false if the waiting time elapsed before the lock could be acquired
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if bean is null
|
||||
*
|
||||
* @see java.util.concurrent.locks.ReentrantLock#tryLock(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
@Override
|
||||
public boolean tryLock(final KP key, final long timeout, final TimeUnit unit) throws InterruptedException {
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
try {
|
||||
return locker.tryLock(key, timeout, unit);
|
||||
} finally {
|
||||
decrementRunningOperations();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "tryLockUnrestricted".
|
||||
*
|
||||
* @param key
|
||||
* @param timeout the time to wait for the lock
|
||||
* @param unit the time unit of the timeout argument
|
||||
* @return true if the lock was free and was acquired by the current thread, or the lock was already held by the
|
||||
* current thread; and false if the waiting time elapsed before the lock could be acquired
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if bean is null
|
||||
*
|
||||
* @see java.util.concurrent.locks.ReentrantLock#tryLock(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
public boolean tryLockUnrestricted(final KP key, final long timeout, final TimeUnit unit) throws InterruptedException {
|
||||
checkStopped();
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
boolean tryLockResultBoolean = false;
|
||||
try {
|
||||
final AtomicBoolean tryLockResult = new AtomicBoolean();
|
||||
final AtomicReference<InterruptedException> interruptedExceptionFromTryRef = new AtomicReference<InterruptedException>();
|
||||
final CyclicBarrier cyclicBarrier = new CyclicBarrier(2);
|
||||
Callable<Boolean> callable = new Callable<Boolean>() {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.util.concurrent.Callable#call()
|
||||
*/
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
boolean locked = false;
|
||||
try {
|
||||
locked = locker.tryLock(key, timeout, unit);
|
||||
tryLockResult.set(locked);
|
||||
} catch (InterruptedException e) {
|
||||
interruptedExceptionFromTryRef.set(e);
|
||||
return false;
|
||||
} finally {
|
||||
// STEP 1
|
||||
cyclicBarrier.await();
|
||||
}
|
||||
if (locked) {
|
||||
// STEP 2
|
||||
cyclicBarrier.await();
|
||||
return locker.unlock(key);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
Future<Boolean> futureTask = threadPool.submit(callable);
|
||||
try {
|
||||
// STEP 1
|
||||
cyclicBarrier.await();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
InterruptedException interruptedExceptionFromTry = interruptedExceptionFromTryRef.get();
|
||||
if (interruptedExceptionFromTry != null) {
|
||||
throw interruptedExceptionFromTry;
|
||||
}
|
||||
tryLockResultBoolean = tryLockResult.get();
|
||||
if (tryLockResultBoolean) {
|
||||
LockerValue<KP> lockerValue = locker.getLockerValue(key);
|
||||
Thread threadLocker = Thread.currentThread();
|
||||
lockerValue.addHandler(new LockerValueHandler(futureTask, cyclicBarrier, threadLocker));
|
||||
locker.traceStackForDebugging(lockerValue);
|
||||
}
|
||||
} finally {
|
||||
decrementRunningOperations();
|
||||
}
|
||||
|
||||
return tryLockResultBoolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "unlock". Unlock the operations with the provided key.
|
||||
*
|
||||
* To detect incorrect unlocking, this method may return an <code>IllegalStateException</code> when the lock has
|
||||
* been already unlocked or it never been locked.
|
||||
*
|
||||
* @param key
|
||||
* @return true if the key has been found to release the lock; and false otherwise
|
||||
* @throws IllegalStateException
|
||||
* @see java.util.concurrent.locks.ReentrantLock#unlock()
|
||||
*/
|
||||
@Override
|
||||
public boolean unlock(final KP key) {
|
||||
boolean returnedValue = false;
|
||||
try {
|
||||
checkStopped();
|
||||
blockOperationIfRequired();
|
||||
incrementRunningOperations();
|
||||
returnedValue = locker.unlock(key);
|
||||
} finally {
|
||||
decrementRunningOperations();
|
||||
}
|
||||
cleanAccordingOperations();
|
||||
return returnedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method "unlockUnrestricted". Unlock the operations with the provided key.
|
||||
*
|
||||
* To detect incorrect unlocking, this method may return an <code>IllegalStateException</code> when the lock has
|
||||
* been already unlocked or it never been locked.
|
||||
*
|
||||
* @param key
|
||||
* @return true if the key has been found to release the lock; and false otherwise
|
||||
* @throws IllegalStateException
|
||||
* @see java.util.concurrent.locks.ReentrantLock#unlock()
|
||||
*/
|
||||
public boolean unlockUnrestricted(final KP key) {
|
||||
checkStopped();
|
||||
blockOperationIfRequired();
|
||||
Boolean resultFuture;
|
||||
incrementRunningOperations();
|
||||
try {
|
||||
LockerValue<KP> lockerValue = locker.getLockerValue(key);
|
||||
if (lockerValue == null) {
|
||||
throw new IllegalStateException(NOT_ALREADY_LOCKED_MESSAGE + " key=" + key);
|
||||
}
|
||||
LockerValueHandler handler = lockerValue.getHandlerAndRemove();
|
||||
if (handler == null) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Either you have to use the restricted unlock() method to unlock, or you have to use '*Lock*Unrestricted()' methods to lock !");
|
||||
}
|
||||
CyclicBarrier barrier = handler.getBarrier();
|
||||
try {
|
||||
// STEP 2
|
||||
barrier.await();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Future<Boolean> future = handler.getFuture();
|
||||
if (future.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
resultFuture = null;
|
||||
try {
|
||||
resultFuture = future.get();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} finally {
|
||||
decrementRunningOperations();
|
||||
}
|
||||
cleanAccordingOperations();
|
||||
return resultFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCleanPeriod() {
|
||||
return cleanPeriod;
|
||||
}
|
||||
|
||||
private void checkStopped() {
|
||||
if (stopped || shuttingDown) {
|
||||
throw new IllegalStateException("This locker is already stopped or is shutting down !");
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanAccordingOperations() {
|
||||
synchronized (lockAllOperations) {
|
||||
int cleanPeriod = getCleanPeriod();
|
||||
if (cleanPeriod > 0 && counter.incrementAndGet() % cleanPeriod == 0) {
|
||||
clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Method "clean".
|
||||
*
|
||||
* Clean the map which contains the lock wrappers.
|
||||
*
|
||||
* Removed lock wrappers are these where lock is not locked by a thread and no one thread is waiting to obtain the
|
||||
* lock.
|
||||
*
|
||||
* The default clean will do an automatic clean all 1000 unlock operation, you can disable or change this value from
|
||||
* the constructor.
|
||||
*/
|
||||
@Override
|
||||
public void clean() {
|
||||
synchronized (lockAllOperations) {
|
||||
waitForRunningOperationsEnded();
|
||||
locker.clean();
|
||||
resumeAllOperations();
|
||||
}
|
||||
}
|
||||
|
||||
private void waitForRunningOperationsEnded() {
|
||||
blockAllOperations();
|
||||
boolean breakAtNext = false;
|
||||
while (true) {
|
||||
Collection<LockerValue<KP>> values = locker.getMapKeyLockToValueLock().values();
|
||||
int waitingThreads = 0;
|
||||
for (LockerValue<KP> lockerValue : values) {
|
||||
waitingThreads += lockerValue.getLock().getQueueLength();
|
||||
}
|
||||
if (runningOperations.get() - waitingThreads <= 0) {
|
||||
if (breakAtNext) {
|
||||
break;
|
||||
}
|
||||
breakAtNext = true;
|
||||
} else {
|
||||
breakAtNext = false;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resumeAllOperations() {
|
||||
this.blockAllOperations = false;
|
||||
lockAllOperations.notifyAll();
|
||||
}
|
||||
|
||||
private void blockAllOperations() {
|
||||
this.blockAllOperations = true;
|
||||
}
|
||||
|
||||
private void blockOperationIfRequired() {
|
||||
if (blockAllOperations) {
|
||||
synchronized (lockAllOperations) {
|
||||
if (blockAllOperations) {
|
||||
try {
|
||||
lockAllOperations.wait();
|
||||
} catch (InterruptedException e) {
|
||||
log.warn(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void decrementRunningOperations() {
|
||||
runningOperations.decrementAndGet();
|
||||
}
|
||||
|
||||
private void incrementRunningOperations() {
|
||||
runningOperations.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void shutdownNow() {
|
||||
shuttingDown = true;
|
||||
locker.shutdownNow();
|
||||
threadPool.shutdownNow();
|
||||
stopped = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void shutdown() {
|
||||
shuttingDown = true;
|
||||
locker.shutdown();
|
||||
threadPool.shutdown();
|
||||
stopped = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockerValue<KP> getLockerValue(KP key) {
|
||||
return locker.getLockerValue(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocked(KP key) {
|
||||
return locker.isLocked(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LockerValue<KP>> getSuspectLocks(long timeDetectionLimitMs) {
|
||||
return locker.getSuspectLocks(timeDetectionLimitMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDetectSuspectLocks(boolean detectSuspectLocks) {
|
||||
locker.setDetectSuspectLocks(detectSuspectLocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDetectSuspectLocks() {
|
||||
return locker.isDetectSuspectLocks();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
package org.talend.commons.utils.threading.lockerbykey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.talend.commons.utils.StringUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* LockerValue.<br/>
|
||||
*
|
||||
* @param <VKP> key
|
||||
*/
|
||||
public class LockerValue<VKP> {
|
||||
|
||||
private CustomReentrantLock lock;
|
||||
|
||||
private VKP key;
|
||||
|
||||
private List<LockerValueHandler> handlers;
|
||||
|
||||
private StackTraceElement[] stackTraceOfLocker;
|
||||
|
||||
private long lockedTime;
|
||||
|
||||
/**
|
||||
* LockerValue constructor.
|
||||
*
|
||||
* @param thread
|
||||
* @param contextInfo
|
||||
* @param fair
|
||||
*/
|
||||
public LockerValue(VKP key, boolean fair) {
|
||||
this.lock = new CustomReentrantLock(fair);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return StringUtils.replacePrms("LockerValue: key={0}, lock={1}", String.valueOf(key), lock.toString()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for key.
|
||||
*
|
||||
* @return the key
|
||||
*/
|
||||
public VKP getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for lock.
|
||||
*
|
||||
* @return the lock
|
||||
*/
|
||||
public CustomReentrantLock getLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Method "addHandler". Add handler to internal list.
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public synchronized void addHandler(LockerValueHandler handler) {
|
||||
if (handlers == null) {
|
||||
handlers = new ArrayList<LockerValueHandler>();
|
||||
}
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Method "getHandlerAndRemove".
|
||||
*
|
||||
* Return the next available handler then remove it from internal list, else null if not exist.
|
||||
*
|
||||
* @return the next available handler, else null if not exist
|
||||
*/
|
||||
public synchronized LockerValueHandler getHandler() {
|
||||
if (handlers != null && handlers.size() > 0) {
|
||||
LockerValueHandler lockerValueHandler = handlers.get(0);
|
||||
return lockerValueHandler;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Method "getHandlerAndRemove".
|
||||
*
|
||||
* Return the next available handler then remove it from internal list, else null if not exist.
|
||||
*
|
||||
* @return the next available handler, else null if not exist
|
||||
*/
|
||||
public synchronized LockerValueHandler getHandlerAndRemove() {
|
||||
if (handlers != null && handlers.size() > 0) {
|
||||
LockerValueHandler lockerValueHandler = handlers.get(0);
|
||||
handlers.remove(0);
|
||||
return lockerValueHandler;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for stackTraceElements.
|
||||
*
|
||||
* @return the stackTraceElements
|
||||
*/
|
||||
public StackTraceElement[] getStackTraceOfLocker() {
|
||||
return stackTraceOfLocker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the stackTraceElements.
|
||||
*
|
||||
* @param stackTraceElements the stackTraceElements to set
|
||||
*/
|
||||
public void setStackTraceOfLocker(StackTraceElement[] stackTraceElements) {
|
||||
this.stackTraceOfLocker = stackTraceElements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for lockedTime.
|
||||
*
|
||||
* @return the lockedTime
|
||||
*/
|
||||
public long getLockedTime() {
|
||||
return lockedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lockedTime.
|
||||
*
|
||||
* @param lockedTime the lockedTime to set
|
||||
*/
|
||||
public void setLockedTime(long lockedTime) {
|
||||
this.lockedTime = lockedTime;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// 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.commons.utils.threading.lockerbykey;
|
||||
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* class LockerValueHandler.
|
||||
*/
|
||||
public class LockerValueHandler {
|
||||
|
||||
private Future<Boolean> future;
|
||||
|
||||
private CyclicBarrier barrier;
|
||||
|
||||
private Thread callerThreadLocker;
|
||||
|
||||
public LockerValueHandler(Future<Boolean> future, CyclicBarrier barrier, Thread callerThreadLocker) {
|
||||
super();
|
||||
this.future = future;
|
||||
this.barrier = barrier;
|
||||
this.callerThreadLocker = callerThreadLocker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for future.
|
||||
*
|
||||
* @return the future
|
||||
*/
|
||||
public Future<Boolean> getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for barrier.
|
||||
*
|
||||
* @return the barrier
|
||||
*/
|
||||
public CyclicBarrier getBarrier() {
|
||||
return barrier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for callerThreadLocker.
|
||||
*
|
||||
* @return the callerThreadLocker
|
||||
*/
|
||||
public Thread getCallerThreadLocker() {
|
||||
return callerThreadLocker;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2020 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.commons.utils.time;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Hierarchy;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.apache.log4j.RollingFileAppender;
|
||||
import org.apache.log4j.spi.LoggerFactory;
|
||||
import org.apache.log4j.spi.RootLogger;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
public class PerformanceLogManager {
|
||||
|
||||
private Hierarchy hierarchy;
|
||||
|
||||
public PerformanceLogManager() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("log4j.rootCategory", ", A1");
|
||||
properties.put("log4j.appender.A1", RollingFileAppender.class.getName());
|
||||
IPath performanceLogPath = Platform.getLogFileLocation().removeLastSegments(1).append("performance.log");
|
||||
properties.put("log4j.appender.A1.File", performanceLogPath.toOSString());
|
||||
properties.put("log4j.appender.A1.MaxBackupIndex", "10");// same as .log's max backup log file count
|
||||
properties.put("log4j.appender.A1.MaxFileSize", "1000000");//1000*1000 byte, same as .log's max file size
|
||||
properties.put("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout");
|
||||
properties.put("log4j.appender.A1.layout.ConversionPattern", "%d %-5p %c %x - %m%n");
|
||||
|
||||
this.hierarchy = new Hierarchy(new RootLogger(Level.INFO));
|
||||
new PropertyConfigurator().doConfigure(properties,hierarchy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this PluginLogManager is disabled for this level.
|
||||
* @param level level value
|
||||
* @return boolean true if it is disabled
|
||||
*/
|
||||
public boolean isDisabled(int level) {
|
||||
return this.hierarchy.isDisabled(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable logging for logging requests with level l or higher.
|
||||
* By default all levels are enabled.
|
||||
* @param level level object
|
||||
*/
|
||||
public void setThreshold(Level level) {
|
||||
this.hierarchy.setThreshold(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* The string version of setThreshold(Level level)
|
||||
* @param level level string
|
||||
*/
|
||||
public void setThreshold(String level) {
|
||||
this.hierarchy.setThreshold(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the repository-wide threshold.
|
||||
* @return Level
|
||||
*/
|
||||
public Level getThreshold() {
|
||||
return this.hierarchy.getThreshold();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new logger instance named as the first parameter
|
||||
* using the default factory. If a logger of that name already exists,
|
||||
* then it will be returned. Otherwise, a new logger will be instantiated
|
||||
* and then linked with its existing ancestors as well as children.
|
||||
* @param name logger name
|
||||
* @return Logger
|
||||
*/
|
||||
public Logger getLogger(String name) {
|
||||
return this.hierarchy.getLogger(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* The same as getLogger(String name) but using a factory instance instead of
|
||||
* a default factory.
|
||||
* @param name logger name
|
||||
* @param factory factory instance
|
||||
* @return Logger
|
||||
*/
|
||||
public Logger getLogger(String name, LoggerFactory factory) {
|
||||
return this.hierarchy.getLogger(name,factory);
|
||||
}
|
||||
|
||||
public Logger getRootLogger() {
|
||||
return this.hierarchy.getRootLogger();
|
||||
}
|
||||
|
||||
public Logger exists(String name) {
|
||||
return this.hierarchy.exists(name);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.hierarchy.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the loggers in this manager.
|
||||
* @return Enumeration logger enumeration
|
||||
*/
|
||||
public Enumeration getCurrentLoggers() {
|
||||
return this.hierarchy.getCurrentLoggers();
|
||||
}
|
||||
|
||||
public void resetConfiguration() {
|
||||
this.hierarchy.resetConfiguration();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2020 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.commons.utils.time;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.talend.commons.exception.CommonExceptionHandler;
|
||||
|
||||
/**
|
||||
* DOC sbliu class global comment. Detailled comment
|
||||
*/
|
||||
public class PerformanceStatisticUtil {
|
||||
|
||||
private static final DecimalFormat DF = new DecimalFormat("###.##");
|
||||
|
||||
private static final int MEGABYTE = 1024 * 1024;// MB = 1024*1024 byte
|
||||
|
||||
private static final int KILOBYTE = 1024;// kb=1024 byte
|
||||
|
||||
private static final int numOfBlocks = 256;
|
||||
|
||||
private static final int blockSizeKb = 512;
|
||||
|
||||
private static final String dataFile = "testio.data";
|
||||
|
||||
private static String recordingFileName = "performance_record";
|
||||
|
||||
private static File recordingFile = null;
|
||||
|
||||
private static enum BlockSequence {
|
||||
SEQUENTIAL,
|
||||
RANDOM;
|
||||
}
|
||||
|
||||
public static enum StatisticKeys {
|
||||
|
||||
IO_COUNT("I/O.count"), // io count
|
||||
IO_W_MB_SEC("I/O.write"), // write speed MB
|
||||
IO_R_MB_SEC("I/O.read"), // read speed MB
|
||||
IO_W_AVERAGE_MB_SEC("I/O.write.average"), // average speed of write MB
|
||||
IO_R_AVERAGE_MB_SEC("I/O.read.average"), // average speed of read
|
||||
|
||||
STARTUP_AVERAGE("startup.average"),
|
||||
STARTUP_MAX("startup.max"),
|
||||
STARTUP_COUNT("startup.count");
|
||||
|
||||
private String key;
|
||||
|
||||
StatisticKeys(String _key) {
|
||||
key = _key;
|
||||
}
|
||||
|
||||
public String get() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public static void recordStartupEpapsedTime(double elapsedTimeInSeconds) {
|
||||
File file = getRecordingFile();
|
||||
|
||||
Properties props = read(file, true);
|
||||
String propCount = props.getProperty(StatisticKeys.STARTUP_COUNT.get(), "0");
|
||||
String propMax = props.getProperty(StatisticKeys.STARTUP_MAX.get(), "0");
|
||||
String propAverage = props.getProperty(StatisticKeys.STARTUP_AVERAGE.get(), "0");
|
||||
|
||||
int iPropCount = Integer.parseInt(propCount);
|
||||
double iPropMax = Double.parseDouble(propMax);
|
||||
double iPropAverage = Double.parseDouble(propAverage);
|
||||
|
||||
iPropMax = iPropMax > elapsedTimeInSeconds ? iPropMax : elapsedTimeInSeconds;
|
||||
iPropAverage = (iPropAverage * iPropCount + elapsedTimeInSeconds) / (iPropCount + 1);
|
||||
iPropCount++;
|
||||
|
||||
props.setProperty(StatisticKeys.STARTUP_COUNT.get(), "" + iPropCount);
|
||||
props.setProperty(StatisticKeys.STARTUP_MAX.get(), "" + iPropMax);
|
||||
props.setProperty(StatisticKeys.STARTUP_AVERAGE.get(), "" + iPropAverage);
|
||||
|
||||
store(file, props);
|
||||
}
|
||||
|
||||
public static File getRecordingFile() {
|
||||
if (recordingFile != null) {
|
||||
return recordingFile;
|
||||
}
|
||||
|
||||
String configurationLocation = Platform.getConfigurationLocation().getURL().getPath();
|
||||
File file = new File(configurationLocation + "/" + recordingFileName);
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void setRecordingFile(File _recordingFile) {
|
||||
recordingFile = _recordingFile;
|
||||
}
|
||||
|
||||
public static synchronized Properties read(File recordFile, boolean createIfNotExist) {
|
||||
Properties props = new Properties();
|
||||
if (recordFile != null && exist(recordFile, createIfNotExist)) {
|
||||
FileInputStream inStream = null;
|
||||
try {
|
||||
inStream = new FileInputStream(recordFile);
|
||||
props.load(inStream);
|
||||
} catch (Exception e) {
|
||||
CommonExceptionHandler.log(e.getMessage());
|
||||
} finally {
|
||||
if (inStream != null) {
|
||||
try {
|
||||
inStream.close();
|
||||
} catch (IOException e) {//
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
public static synchronized void store(File recordFile, Properties props) {
|
||||
if (props == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (recordFile != null && exist(recordFile, true)) {
|
||||
FileOutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = new FileOutputStream(recordFile);
|
||||
props.store(outputStream, "");
|
||||
} catch (IOException e) {
|
||||
CommonExceptionHandler.log(e.getMessage());
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean exist(File recordFile, boolean createIfNotExist) {
|
||||
boolean exists = recordFile.exists();
|
||||
if (!exists && createIfNotExist) {
|
||||
try {
|
||||
exists = recordFile.createNewFile();
|
||||
if (!exists) {
|
||||
throw new FileNotFoundException(recordFile.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CommonExceptionHandler.log(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
private static Lock lock = new ReentrantLock();
|
||||
private static Condition condition = lock.newCondition();
|
||||
private static boolean measureIOFinished = true;
|
||||
|
||||
public static void waitUntilFinish() throws InterruptedException {
|
||||
lock.lock();
|
||||
|
||||
try {
|
||||
if(!measureIOFinished) {
|
||||
condition.await(20, TimeUnit.SECONDS);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public static void measureIO() {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
measureIOFinished = false;
|
||||
try {
|
||||
_measureIO();
|
||||
} finally {
|
||||
measureIOFinished = true;
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private static void _measureIO() {
|
||||
File file = getRecordingFile();
|
||||
Properties props = read(file, true);
|
||||
|
||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
File workspace = root.getLocation().makeAbsolute().toFile();
|
||||
File locationDir = new File(workspace, "temp"); // here is workspace/temp dir
|
||||
File testFile = detectTestDataFile(locationDir);
|
||||
|
||||
if (testFile != null) {
|
||||
measureWrite(props, testFile);
|
||||
measureRead(props, testFile);
|
||||
|
||||
store(file, props);
|
||||
}
|
||||
}
|
||||
|
||||
private static void measureWrite(Properties props, File testFile) {
|
||||
int blockSize = blockSizeKb * KILOBYTE;
|
||||
|
||||
long startTime = System.nanoTime();
|
||||
long totalBytesWrittenInMark = writeIO(numOfBlocks, BlockSequence.RANDOM, blockSize, testFile);
|
||||
totalBytesWrittenInMark = totalBytesWrittenInMark + writeIO(numOfBlocks, BlockSequence.SEQUENTIAL, blockSize, testFile);
|
||||
long endTime = System.nanoTime();
|
||||
|
||||
long elapsedTimeNs = endTime - startTime;
|
||||
double sec = (double) elapsedTimeNs / (double) 1000000000;
|
||||
double mbWritten = (double) totalBytesWrittenInMark / (double) MEGABYTE;
|
||||
double bwMbSec = mbWritten / sec;
|
||||
|
||||
String ioCount = props.getProperty(StatisticKeys.IO_COUNT.get(), "0");
|
||||
String ioWAverageMbSec = props.getProperty(StatisticKeys.IO_W_AVERAGE_MB_SEC.get(), "0");
|
||||
String ioWMbSec = props.getProperty(StatisticKeys.IO_W_MB_SEC.get(), "0");
|
||||
|
||||
int digital_ioCount = Integer.parseInt(ioCount);
|
||||
double digital_ioWAverageMbSec = Double.parseDouble(ioWAverageMbSec);
|
||||
double digital_ioWMbSec = Double.parseDouble(ioWMbSec);
|
||||
|
||||
digital_ioWAverageMbSec = (digital_ioWAverageMbSec * digital_ioCount + bwMbSec) / (digital_ioCount + 1);
|
||||
digital_ioWMbSec = bwMbSec;
|
||||
|
||||
props.setProperty(StatisticKeys.IO_W_AVERAGE_MB_SEC.get(), "" + DF.format(digital_ioWAverageMbSec));
|
||||
props.setProperty(StatisticKeys.IO_W_MB_SEC.get(), "" + DF.format(digital_ioWMbSec));
|
||||
}
|
||||
|
||||
private static long writeIO(int numOfBlocks, BlockSequence blockSequence, int blockSize, File testFile) {
|
||||
byte[] blockArr = new byte[blockSize];
|
||||
for (int b = 0; b < blockArr.length; b++) {
|
||||
if (b % 2 == 0) {
|
||||
blockArr[b] = (byte) 0xFF;
|
||||
}
|
||||
}
|
||||
String mode = "rwd";// "rwd"
|
||||
|
||||
long totalBytesWrittenInMark = 0;
|
||||
try {
|
||||
try (RandomAccessFile rAccFile = new RandomAccessFile(testFile, mode)) {
|
||||
for (int b = 0; b < numOfBlocks; b++) {
|
||||
if (blockSequence == BlockSequence.RANDOM) {
|
||||
int rLoc = randInt(0, numOfBlocks - 1);
|
||||
rAccFile.seek(rLoc * blockSize);
|
||||
} else {
|
||||
rAccFile.seek(b * blockSize);
|
||||
}
|
||||
rAccFile.write(blockArr, 0, blockSize);
|
||||
totalBytesWrittenInMark += blockSize;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
CommonExceptionHandler.log(e.getMessage());
|
||||
}
|
||||
|
||||
return totalBytesWrittenInMark;
|
||||
}
|
||||
|
||||
private static File detectTestDataFile(File location) {
|
||||
if (!location.exists()) {
|
||||
location.mkdirs();
|
||||
}
|
||||
|
||||
File testFile = null;
|
||||
try {
|
||||
testFile = new File(location.getAbsolutePath() + File.separator + dataFile);
|
||||
testFile.deleteOnExit();
|
||||
testFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
CommonExceptionHandler.log(e.getMessage());
|
||||
}
|
||||
|
||||
return testFile;
|
||||
}
|
||||
|
||||
public static void measureRead(Properties props, File testFile) {
|
||||
int blockSize = blockSizeKb * KILOBYTE;
|
||||
|
||||
long startTime = System.nanoTime();
|
||||
long totalBytesReadInMark = readIO(numOfBlocks, BlockSequence.RANDOM, blockSize, testFile);
|
||||
totalBytesReadInMark = totalBytesReadInMark + readIO(numOfBlocks, BlockSequence.SEQUENTIAL, blockSize, testFile);
|
||||
long endTime = System.nanoTime();
|
||||
long elapsedTimeNs = endTime - startTime;
|
||||
double sec = (double) elapsedTimeNs / (double) 1000000000;
|
||||
double mbRead = (double) totalBytesReadInMark / (double) MEGABYTE;
|
||||
double bwMbSec = mbRead / sec;
|
||||
|
||||
String ioCount = props.getProperty(StatisticKeys.IO_COUNT.get(), "0");
|
||||
String ioRAverageMbSec = props.getProperty(StatisticKeys.IO_R_AVERAGE_MB_SEC.get(), "0");
|
||||
String ioRMbSec = props.getProperty(StatisticKeys.IO_R_MB_SEC.get(), "0");
|
||||
|
||||
int digital_ioCount = Integer.parseInt(ioCount);
|
||||
double digital_ioRAverageMbSec = Double.parseDouble(ioRAverageMbSec);
|
||||
double digital_ioRMbSec = Double.parseDouble(ioRMbSec);
|
||||
digital_ioRAverageMbSec = (digital_ioRAverageMbSec * digital_ioCount + bwMbSec) / (digital_ioCount + 1);
|
||||
digital_ioRMbSec = bwMbSec;
|
||||
digital_ioCount++;
|
||||
|
||||
props.setProperty(StatisticKeys.IO_R_AVERAGE_MB_SEC.get(), "" + DF.format(digital_ioRAverageMbSec));
|
||||
props.setProperty(StatisticKeys.IO_R_MB_SEC.get(), "" + DF.format(digital_ioRMbSec));
|
||||
props.setProperty(StatisticKeys.IO_COUNT.get(), "" + digital_ioCount);
|
||||
}
|
||||
|
||||
private static long readIO(int numOfBlocks, BlockSequence blockSequence, int blockSize, File testFile) {
|
||||
long totalBytesReadInMark = 0;
|
||||
|
||||
byte[] blockArr = new byte[blockSize];
|
||||
for (int b = 0; b < blockArr.length; b++) {
|
||||
if (b % 2 == 0) {
|
||||
blockArr[b] = (byte) 0xFF;
|
||||
}
|
||||
}
|
||||
try {
|
||||
try (RandomAccessFile rAccFile = new RandomAccessFile(testFile, "r")) {
|
||||
for (int b = 0; b < numOfBlocks; b++) {
|
||||
if (blockSequence == BlockSequence.RANDOM) {
|
||||
int rLoc = randInt(0, numOfBlocks - 1);
|
||||
rAccFile.seek(rLoc * blockSize);
|
||||
} else {
|
||||
rAccFile.seek(b * blockSize);
|
||||
}
|
||||
rAccFile.readFully(blockArr, 0, blockSize);
|
||||
totalBytesReadInMark += blockSize;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
CommonExceptionHandler.log(e.getMessage());
|
||||
}
|
||||
return totalBytesReadInMark;
|
||||
}
|
||||
|
||||
private static int randInt(int min, int max) {
|
||||
// nextInt is normally exclusive of the top value,
|
||||
// so add 1 to make it inclusive
|
||||
int randomNum = new Random().nextInt((max - min) + 1) + min;
|
||||
|
||||
return randomNum;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2020 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.commons.utils.time;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* DOC sbliu class global comment. Detailled comment
|
||||
*/
|
||||
public class TimeMeasurePerformance extends TimeMeasure{
|
||||
static private Logger logger;
|
||||
|
||||
private static HashMap<String, TimeStack> timers;
|
||||
|
||||
private static long startTime = -1L;
|
||||
|
||||
private static int indent = 0;
|
||||
|
||||
public static void begin(String idTimer) {
|
||||
startTime = System.nanoTime();
|
||||
|
||||
init();
|
||||
if (timers.containsKey(idTimer)) {
|
||||
log(indent(indent) + "Warning (start): timer " + idTimer + " already exists"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} else {
|
||||
indent++;
|
||||
TimeStack times = new TimeStack();
|
||||
timers.put(idTimer, times);
|
||||
log(indent(indent) + "Start '" + idTimer + "' ..."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
private static void init() {
|
||||
if (timers == null) {
|
||||
timers = new HashMap<String, TimeStack>();
|
||||
}
|
||||
|
||||
if(logger == null) {
|
||||
configureLogger();
|
||||
}
|
||||
}
|
||||
|
||||
private static void log (String message) {
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
public static long end(String idTimer) {
|
||||
init();
|
||||
if (!timers.containsKey(idTimer)) {
|
||||
log(indent(indent) + "Warning (end): timer " + idTimer + " doesn't exist"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return -1;
|
||||
} else {
|
||||
TimeStack timeStack = timers.get(idTimer);
|
||||
timers.remove(idTimer);
|
||||
long elapsedTimeSinceLastRequest = timeStack.getLastStepElapsedTime();
|
||||
log(indent(indent) + "End '" + idTimer + "', elapsed time since last request: " //$NON-NLS-1$ //$NON-NLS-2$
|
||||
+ elapsedTimeSinceLastRequest + " ms "); //$NON-NLS-1$
|
||||
|
||||
long totalElapsedTime = timeStack.getTotalElapsedTime();
|
||||
|
||||
log(indent(indent) + "End '" + idTimer + "', total elapsed time: " + totalElapsedTime + " ms "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
indent--;
|
||||
return totalElapsedTime;
|
||||
}
|
||||
}
|
||||
|
||||
public static long step(String idTimer, String stepName) {
|
||||
init();
|
||||
if (!timers.containsKey(idTimer)) {
|
||||
log(indent(indent) + "Warning (end): timer " + idTimer + " does'nt exist"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return -1;
|
||||
} else {
|
||||
TimeStack timeStack = timers.get(idTimer);
|
||||
timeStack.addStep();
|
||||
/*
|
||||
* trace the timeline of every step,problem is that the code below " Calendar ca = Calendar.getInstance();
|
||||
* Date now = ca.getTime();" will cost almost 13ms~15ms
|
||||
*/
|
||||
long time = timeStack.getLastStepElapsedTime();
|
||||
String timerStepName = idTimer + "', step name '" + stepName; //$NON-NLS-1$
|
||||
|
||||
log(indent(indent)
|
||||
+ "-> '" + timerStepName + "', elapsed time since previous step: " + time + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureLogger() {
|
||||
try {
|
||||
PerformanceLogManager logManager = new PerformanceLogManager();
|
||||
logger = logManager.getLogger(TimeMeasurePerformance.class.getName());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error while initializing log properties.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void afterStartup() {
|
||||
double elapsedTimeInSeconds = (double)(System.nanoTime() - startTime)/1000000000;
|
||||
PerformanceStatisticUtil.recordStartupEpapsedTime(elapsedTimeInSeconds);
|
||||
PerformanceStatisticUtil.measureIO();
|
||||
}
|
||||
}
|
||||
@@ -212,4 +212,8 @@ public class CommonTextCellEditorWithProposal {
|
||||
return this.contentProposalAdapter;
|
||||
}
|
||||
|
||||
public int getPreviousActivatedIndex() {
|
||||
return previousActivatedIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -97,4 +97,7 @@ public class ExtendedTextCellEditorWithProposal extends ExtendedTextCellEditor i
|
||||
super.fireCancelEditor();
|
||||
}
|
||||
|
||||
public CommonTextCellEditorWithProposal getCommonTextEditor() {
|
||||
return commonTextEditor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,4 +67,9 @@ public class SyncLibrariesLoginTask extends AbstractLoginTask implements IRunnab
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRequiredAlways() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -837,8 +837,8 @@ public abstract class AbstractEMFRepositoryFactory extends AbstractRepositoryFac
|
||||
Object fullFolder = getFullFolder(project, type, relativeFolder);
|
||||
serializableAllVersion = getSerializableFromFolder(project, fullFolder, id, type, false, false, true, true);
|
||||
if (serializableAllVersion.isEmpty()) {
|
||||
// look in all folders
|
||||
serializableAllVersion = getSerializable(project, id, false, false);
|
||||
// look in all folders for this item type
|
||||
serializableAllVersion = getSerializableFromFolder(project, fullFolder, id, type, false, true, true, true, true);
|
||||
}
|
||||
int size = serializableAllVersion.size();
|
||||
|
||||
|
||||
@@ -270,6 +270,8 @@ public interface IRepositoryFactory {
|
||||
|
||||
public void create(Project project, Item item, IPath path, boolean... isImportItem) throws PersistenceException;
|
||||
|
||||
public void save(Project project, Item item, boolean isMigrationTask) throws PersistenceException;
|
||||
|
||||
public void save(Project project, Item item) throws PersistenceException;
|
||||
|
||||
public void save(Project project, Property property) throws PersistenceException;
|
||||
|
||||
@@ -1066,6 +1066,9 @@ public class ProjectRepositoryNode extends RepositoryNode implements IProjectRep
|
||||
}
|
||||
if (newProject != null && newProject.getEmfProject() != null) {
|
||||
List<FolderItem> folderItems = ProjectManager.getInstance().getFolders(newProject.getEmfProject());
|
||||
if (folderItems != null) {
|
||||
folderItems = new ArrayList<>(folderItems);
|
||||
}
|
||||
for (FolderItem folder : folderItems) {
|
||||
String folderName = folder.getProperty().getLabel();
|
||||
if (("process".equals(folderName) || "joblets".equals(folderName)) && folder.getChildren() != null
|
||||
|
||||
@@ -15,6 +15,7 @@ package org.talend.core.repository.model;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -71,7 +72,7 @@ import org.talend.commons.ui.gmf.util.DisplayUtils;
|
||||
import org.talend.commons.ui.runtime.exception.MessageBoxExceptionHandler;
|
||||
import org.talend.commons.utils.data.container.RootContainer;
|
||||
import org.talend.commons.utils.network.TalendProxySelector;
|
||||
import org.talend.commons.utils.time.TimeMeasure;
|
||||
import org.talend.commons.utils.time.TimeMeasurePerformance;
|
||||
import org.talend.commons.utils.workbench.resources.ResourceUtils;
|
||||
import org.talend.core.AbstractDQModelService;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
@@ -84,6 +85,7 @@ import org.talend.core.context.Context;
|
||||
import org.talend.core.context.RepositoryContext;
|
||||
import org.talend.core.exception.TalendInternalPersistenceException;
|
||||
import org.talend.core.hadoop.BigDataBasicUtil;
|
||||
import org.talend.core.model.general.ILibrariesService;
|
||||
import org.talend.core.model.general.ModuleNeeded;
|
||||
import org.talend.core.model.general.Project;
|
||||
import org.talend.core.model.metadata.MetadataTalendType;
|
||||
@@ -124,6 +126,7 @@ import org.talend.core.repository.constants.Constant;
|
||||
import org.talend.core.repository.constants.FileConstants;
|
||||
import org.talend.core.repository.i18n.Messages;
|
||||
import org.talend.core.repository.recyclebin.RecycleBinManager;
|
||||
import org.talend.core.repository.utils.LoginTaskRegistryReader;
|
||||
import org.talend.core.repository.utils.ProjectDataJsonProvider;
|
||||
import org.talend.core.repository.utils.RepositoryPathProvider;
|
||||
import org.talend.core.repository.utils.XmiResourceManager;
|
||||
@@ -132,10 +135,10 @@ import org.talend.core.runtime.repository.item.ItemProductKeys;
|
||||
import org.talend.core.runtime.services.IMavenUIService;
|
||||
import org.talend.core.runtime.util.ItemDateParser;
|
||||
import org.talend.core.service.ICoreUIService;
|
||||
import org.talend.core.service.IUpdateService;
|
||||
import org.talend.cwm.helper.SubItemHelper;
|
||||
import org.talend.cwm.helper.TableHelper;
|
||||
import org.talend.designer.runprocess.IRunProcessService;
|
||||
import org.talend.login.ILoginTask;
|
||||
import org.talend.repository.ProjectManager;
|
||||
import org.talend.repository.ReferenceProjectProblemManager;
|
||||
import org.talend.repository.ReferenceProjectProvider;
|
||||
@@ -177,6 +180,8 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
|
||||
private boolean isCancelled;
|
||||
|
||||
private static final LoginTaskRegistryReader LOGIN_TASK_REGISTRY_READER = new LoginTaskRegistryReader();
|
||||
|
||||
@Override
|
||||
public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
if (l == null) {
|
||||
@@ -226,6 +231,13 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ILibrariesService getLibrariesService() {
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
|
||||
return GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
@@ -1213,6 +1225,28 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
return this.repositoryFactoryFromProvider.getLastVersion(project, ProcessUtils.getPureItemId(id), folderPath, type);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IRepositoryViewObject getLastVersion(String id, ERepositoryObjectType type)
|
||||
throws PersistenceException {
|
||||
return getLastVersion(id , "", type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRepositoryViewObject getLastVersion(String id, List<ERepositoryObjectType> types) throws PersistenceException {
|
||||
if (types != null) {
|
||||
IRepositoryViewObject object = null;
|
||||
for (ERepositoryObjectType type : types) {
|
||||
object = getLastVersion(id, type);
|
||||
if (object != null) {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRepositoryViewObject getLastVersion(String id, String folderPath, ERepositoryObjectType type)
|
||||
throws PersistenceException {
|
||||
String objId = id;
|
||||
@@ -1224,7 +1258,25 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
return this.repositoryFactoryFromProvider.getLastVersion(project, objId, folderPath, type);
|
||||
}
|
||||
}
|
||||
return this.repositoryFactoryFromProvider.getLastVersion(projectManager.getCurrentProject(), objId , folderPath, type);
|
||||
return getLastRefVersion(projectManager.getCurrentProject(), objId , folderPath, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRepositoryViewObject getLastRefVersion(Project project, String id, String folderPath, ERepositoryObjectType type) throws PersistenceException {
|
||||
String projectLabel = ProcessUtils.getProjectLabelFromItemId(id);
|
||||
IRepositoryViewObject lastVersion = getLastVersion(project, ProcessUtils.getPureItemId(id), folderPath, type);
|
||||
if (lastVersion == null) {
|
||||
for (Project p : projectManager.getReferencedProjects(project)) {
|
||||
if (projectLabel != null && !projectLabel.equals(p.getTechnicalLabel())) {
|
||||
continue;
|
||||
}
|
||||
lastVersion = getLastRefVersion(p, id);
|
||||
if (lastVersion != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lastVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1442,7 +1494,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
String folderName = parentPath.append(folderLabel).toString();
|
||||
boolean found = false;
|
||||
for (String existedFolder : folders) {
|
||||
if (folderName.toUpperCase().equals(existedFolder.toUpperCase())) {
|
||||
if (folderName.equalsIgnoreCase(existedFolder)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -1546,14 +1598,15 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
|
||||
@Override
|
||||
public void save(Project project, Item item, boolean... isMigrationTask) throws PersistenceException {
|
||||
this.repositoryFactoryFromProvider.save(project, item);
|
||||
if (isMigrationTask == null || isMigrationTask.length == 0 || !isMigrationTask[0]) {
|
||||
this.repositoryFactoryFromProvider.save(project, item);
|
||||
boolean avoidGenerateProm = false;
|
||||
if (isMigrationTask != null && isMigrationTask.length == 2) {
|
||||
avoidGenerateProm = isMigrationTask[1];
|
||||
}
|
||||
fireRepositoryPropertyChange(ERepositoryActionName.SAVE.getName(), avoidGenerateProm, item);
|
||||
|
||||
} else {
|
||||
this.repositoryFactoryFromProvider.save(project, item, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2035,11 +2088,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
*/
|
||||
public void logOnProject(Project project, IProgressMonitor monitor) throws LoginException, PersistenceException {
|
||||
try {
|
||||
TimeMeasure.display = CommonsPlugin.isDebugMode();
|
||||
TimeMeasure.displaySteps = CommonsPlugin.isDebugMode();
|
||||
TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
|
||||
|
||||
TimeMeasure.begin("logOnProject"); //$NON-NLS-1$
|
||||
TimeMeasurePerformance.begin("logOnProject"); //$NON-NLS-1$
|
||||
try {
|
||||
/**
|
||||
* init/check proxy selector, in case default proxy selector is not registed yet
|
||||
@@ -2083,6 +2132,10 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
this.repositoryFactoryFromProvider.beforeLogon(project);
|
||||
ProjectManager.getInstance().getBeforeLogonRecords().clear();
|
||||
ProjectManager.getInstance().getUpdatedRemoteHandlerRecords().clear();
|
||||
ILibrariesService librariesService = getLibrariesService();
|
||||
if (librariesService != null) {
|
||||
librariesService.setForceReloadCustomUri();
|
||||
}
|
||||
|
||||
ProjectDataJsonProvider.checkAndRectifyRelationShipSetting(project.getEmfProject());
|
||||
|
||||
@@ -2106,7 +2159,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
throw new OperationCanceledException(""); //$NON-NLS-1$
|
||||
}
|
||||
// monitorWrap.worked(1);
|
||||
TimeMeasure.step("logOnProject", "beforeLogon"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TimeMeasurePerformance.step("logOnProject", "beforeLogon"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
// Check project compatibility
|
||||
checkProjectCompatibility(project);
|
||||
@@ -2124,7 +2177,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
currentMonitor = subMonitor.newChild(1, SubMonitor.SUPPRESS_NONE);
|
||||
currentMonitor.beginTask(Messages.getString("ProxyRepositoryFactory.synchronizeLibraries"), 1); //$NON-NLS-1$
|
||||
coreService.syncLibraries(currentMonitor);
|
||||
TimeMeasure.step("logOnProject", "Sync components libraries"); //$NON-NLS-1$
|
||||
TimeMeasurePerformance.step("logOnProject", "Sync components libraries"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
currentMonitor = subMonitor.newChild(1, SubMonitor.SUPPRESS_NONE);
|
||||
@@ -2133,7 +2186,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
executeMigrations(project, true, currentMonitor);
|
||||
ProjectManager.getInstance().getMigrationRecords().clear();
|
||||
// monitorWrap.worked(1);
|
||||
TimeMeasure.step("logOnProject", "executeMigrations(beforeLogonTasks)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TimeMeasurePerformance.step("logOnProject", "executeMigrations(beforeLogonTasks)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
currentMonitor = subMonitor.newChild(1, SubMonitor.SUPPRESS_NONE);
|
||||
currentMonitor.beginTask(Messages.getString("ProxyRepositoryFactory.logonInProgress"), 1); //$NON-NLS-1$
|
||||
@@ -2141,7 +2194,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
this.repositoryFactoryFromProvider.logOnProject(project);
|
||||
ProjectManager.getInstance().getLogonRecords().clear();
|
||||
// monitorWrap.worked(1);
|
||||
TimeMeasure.step("logOnProject", "logOnProject"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TimeMeasurePerformance.step("logOnProject", "logOnProject"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
emptyTempFolder(project);
|
||||
|
||||
@@ -2157,11 +2210,6 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
|
||||
fireRepositoryPropertyChange(ERepositoryActionName.PROJECT_PREFERENCES_RELOAD.getName(), null, null);
|
||||
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(IUpdateService.class)) {
|
||||
IUpdateService updateService = GlobalServiceRegister.getDefault().getService(IUpdateService.class);
|
||||
updateService.syncComponentM2Jars(currentMonitor);
|
||||
}
|
||||
|
||||
IRunProcessService runProcessService = getRunProcessService();
|
||||
if (runProcessService != null) {
|
||||
runProcessService.initMavenJavaProject(monitor, project);
|
||||
@@ -2172,7 +2220,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
ProjectManager.getInstance().getMigrationRecords().clear();
|
||||
executeMigrations(project, false, currentMonitor);
|
||||
ProjectManager.getInstance().getMigrationRecords().clear();
|
||||
TimeMeasure.step("logOnProject", "executeMigrations(afterLogonTasks)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TimeMeasurePerformance.step("logOnProject", "executeMigrations(afterLogonTasks)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if (monitor != null && monitor.isCanceled()) {
|
||||
throw new OperationCanceledException(""); //$NON-NLS-1$
|
||||
}
|
||||
@@ -2188,12 +2236,12 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
// clean workspace
|
||||
currentMonitor.beginTask(Messages.getString("ProxyRepositoryFactory.cleanWorkspace"), 1); //$NON-NLS-1$
|
||||
|
||||
TimeMeasure.step("logOnProject", "clean Java project"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TimeMeasurePerformance.step("logOnProject", "clean Java project"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
if (workspace instanceof Workspace) {
|
||||
((Workspace) workspace).getFileSystemManager().getHistoryStore().clean(currentMonitor);
|
||||
}
|
||||
TimeMeasure.step("logOnProject", "clean workspace history"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TimeMeasurePerformance.step("logOnProject", "clean workspace history"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
currentMonitor = subMonitor.newChild(1, SubMonitor.SUPPRESS_NONE);
|
||||
currentMonitor.beginTask(Messages.getString("ProxyRepositoryFactory.synch.repo.items"), 1); //$NON-NLS-1$
|
||||
@@ -2219,12 +2267,12 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
if (monitor != null && monitor.isCanceled()) {
|
||||
throw new OperationCanceledException(""); //$NON-NLS-1$
|
||||
}
|
||||
TimeMeasure.step("logOnProject", "sync repository (routines/rules/beans)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TimeMeasurePerformance.step("logOnProject", "sync repository (routines/rules/beans)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
// log4j prefs
|
||||
if (coreUiService != null && coreService != null) {
|
||||
coreService.syncLog4jSettings(null);
|
||||
TimeMeasure.step("logOnProject", "sync log4j"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TimeMeasurePerformance.step("logOnProject", "sync log4j"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -2233,6 +2281,8 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
// set the project mappings url
|
||||
System.setProperty("talend.mappings.url", url.toString()); // $NON-NLS-1$
|
||||
}
|
||||
// for new added mapping file, sync to project mapping folder
|
||||
MetadataTalendType.syncNewMappingFileToProject();
|
||||
} catch (SystemException e) {
|
||||
// ignore
|
||||
ExceptionHandler.process(e);
|
||||
@@ -2241,7 +2291,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
if (runProcessService != null && !isCommandLineLocalRefProject) {
|
||||
runProcessService.initializeRootPoms(monitor);
|
||||
|
||||
TimeMeasure.step("logOnProject", "install / setup root poms"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TimeMeasurePerformance.step("logOnProject", "install / setup root poms"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
|
||||
ITDQRepositoryService tdqRepositoryService = GlobalServiceRegister.getDefault()
|
||||
@@ -2258,10 +2308,7 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
fullLogonFinished = true;
|
||||
this.repositoryFactoryFromProvider.afterLogon(monitor);
|
||||
} finally {
|
||||
TimeMeasure.end("logOnProject"); //$NON-NLS-1$
|
||||
TimeMeasure.display = false;
|
||||
TimeMeasure.displaySteps = false;
|
||||
TimeMeasure.measureActive = false;
|
||||
TimeMeasurePerformance.end("logOnProject"); //$NON-NLS-1$
|
||||
}
|
||||
String str[] = new String[] { getRepositoryContext().getUser() + "", projectManager.getCurrentProject() + "" }; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
log.info(Messages.getString("ProxyRepositoryFactory.log.loggedOn", str)); //$NON-NLS-1$
|
||||
@@ -2662,4 +2709,13 @@ public final class ProxyRepositoryFactory implements IProxyRepositoryFactory {
|
||||
public RepositoryWorkUnit getWorkUnitInProgress() {
|
||||
return repositoryFactoryFromProvider.getWorkUnitInProgress();
|
||||
}
|
||||
|
||||
public void executeRequiredLoginTasks(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||
ILoginTask[] allLoginTasks = LOGIN_TASK_REGISTRY_READER.getAllTaskListInstance();
|
||||
for (ILoginTask task : allLoginTasks) {
|
||||
if (task.isRequiredAlways()) {
|
||||
task.run(monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ package org.talend.core.repository.recyclebin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -26,6 +27,7 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.PredicateUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
@@ -281,6 +283,38 @@ public class RecycleBinManager {
|
||||
resource = createRecycleBinResource(project);
|
||||
}
|
||||
resource.getContents().clear();
|
||||
EList<String> deletedFolders = recycleBin.getDeletedFolders();
|
||||
if (deletedFolders != null) {
|
||||
List<String> folders = new LinkedList<>(deletedFolders);
|
||||
Collections.sort(folders);
|
||||
deletedFolders.clear();
|
||||
deletedFolders.addAll(folders);
|
||||
}
|
||||
EList<TalendItem> deletedItems = recycleBin.getDeletedItems();
|
||||
if (deletedItems != null) {
|
||||
List<TalendItem> items = new LinkedList<>(deletedItems);
|
||||
items.sort((l, r) -> {
|
||||
if (l == null && r == null) {
|
||||
return 0;
|
||||
} else if (l == null) {
|
||||
return -1;
|
||||
} else if (r == null) {
|
||||
return 1;
|
||||
}
|
||||
int result = StringUtils.compare(l.getType(), r.getType());
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
result = StringUtils.compare(l.getPath(), r.getPath());
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
return StringUtils.compare(l.getId(), r.getId());
|
||||
});
|
||||
deletedItems.clear();
|
||||
deletedItems.addAll(items);
|
||||
}
|
||||
|
||||
// set date to null to avoid timezone conflict
|
||||
recycleBin.setLastUpdate(null);
|
||||
resource.getContents().add(recycleBin);
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Priority;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
@@ -37,6 +38,7 @@ import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
@@ -69,6 +71,7 @@ import org.talend.core.model.properties.ValidationRulesConnectionItem;
|
||||
import org.talend.core.model.properties.helper.ByteArrayResource;
|
||||
import org.talend.core.model.repository.ERepositoryObjectType;
|
||||
import org.talend.core.repository.constants.FileConstants;
|
||||
import org.talend.core.repository.model.ProxyRepositoryFactory;
|
||||
import org.talend.core.repository.utils.ResourceFilenameHelper.FileName;
|
||||
import org.talend.core.ui.ITestContainerProviderService;
|
||||
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
|
||||
@@ -647,6 +650,23 @@ public class XmiResourceManager {
|
||||
}
|
||||
|
||||
public void saveResource(Resource resource) throws PersistenceException {
|
||||
try {
|
||||
if (resource != null) {
|
||||
Object objectByType = EcoreUtil.getObjectByType(resource.getContents(), PropertiesPackage.eINSTANCE.getProject());
|
||||
if (objectByType != null) {
|
||||
Project project = (Project) objectByType;
|
||||
EList migrationTasks = project.getMigrationTask();
|
||||
if (migrationTasks != null && 1 < migrationTasks.size()) {
|
||||
org.talend.commons.exception.ExceptionHandler.process(new Exception("Bad saving logic for Project"),
|
||||
Priority.WARN);
|
||||
ProxyRepositoryFactory.getInstance().saveProject(new org.talend.core.model.general.Project(project));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
org.talend.commons.exception.ExceptionHandler.process(e);
|
||||
}
|
||||
EmfHelper.saveResource(resource);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<?xml version="1.0"?>
|
||||
<mapping>
|
||||
<dbms product="DATABRICKS_DELTA_LAKE" id="databricks_delta_lake_id" label="Mapping Delta Lake" default="true">
|
||||
<dbTypes>
|
||||
<dbType type="SMALLINT" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="FLOAT" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="DOUBLE" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="BIGINT" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="INT" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="TINYINT" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="STRING" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="DECIMAL" ignoreLen="false" ignorePre="false"/>
|
||||
<dbType type="BOOLEAN" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="STRUCT" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="MAP" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="ARRAY" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="TIMESTAMP" ignoreLen="true" ignorePre="true"/>
|
||||
<dbType type="DATE" ignoreLen="true" ignorePre="true"/>
|
||||
</dbTypes>
|
||||
|
||||
<language name="java">
|
||||
<talendToDbTypes><!-- Adviced mappings -->
|
||||
<talendType type="id_List"/>
|
||||
<talendType type="id_Boolean">
|
||||
<dbType type="BOOLEAN" default="true"/>
|
||||
</talendType>
|
||||
<talendType type="id_Byte">
|
||||
<dbType type="TINYINT" default="true"/>
|
||||
<dbType type="BIGINT"/>
|
||||
<dbType type="INT"/>
|
||||
<dbType type="SMALLINT"/>
|
||||
</talendType>
|
||||
<talendType type="id_byte[]"/>
|
||||
<talendType type="id_Character">
|
||||
<dbType type="STRING" default="true"/>
|
||||
</talendType>
|
||||
<talendType type="id_Date">
|
||||
<dbType type="TIMESTAMP" default="true"/>
|
||||
<dbType type="DATE"/>
|
||||
</talendType>
|
||||
<talendType type="id_BigDecimal">
|
||||
<dbType type="DECIMAL" default="true"/>
|
||||
<dbType type="BIGINT"/>
|
||||
<dbType type="FLOAT"/>
|
||||
<dbType type="DOUBLE"/>
|
||||
</talendType>
|
||||
<talendType type="id_Double">
|
||||
<dbType type="DOUBLE" default="true" />
|
||||
<dbType type="FLOAT"/>
|
||||
</talendType>
|
||||
<talendType type="id_Float">
|
||||
<dbType type="FLOAT" default="true" />
|
||||
<dbType type="DOUBLE"/>
|
||||
</talendType>
|
||||
<talendType type="id_Integer">
|
||||
<dbType type="INT" default="true" />
|
||||
<dbType type="BIGINT" />
|
||||
</talendType>
|
||||
<talendType type="id_Long">
|
||||
<dbType type="BIGINT" default="true" />
|
||||
</talendType>
|
||||
<talendType type="id_Object">
|
||||
<dbType type="STRUCT" default="true" />
|
||||
<dbType type="MAP" />
|
||||
<dbType type="ARRAY" />
|
||||
</talendType>
|
||||
<talendType type="id_Short">
|
||||
<dbType type="SMALLINT" default="true" />
|
||||
<dbType type="INT" />
|
||||
</talendType>
|
||||
<talendType type="id_String">
|
||||
<dbType type="STRING" default="true"/>
|
||||
</talendType>
|
||||
</talendToDbTypes>
|
||||
<dbToTalendTypes><!-- Adviced mappings -->
|
||||
<dbType type="STRING">
|
||||
<talendType type="id_String" default="true"/>
|
||||
</dbType>
|
||||
<dbType type="BOOLEAN">
|
||||
<talendType type="id_Boolean" default="true"/>
|
||||
</dbType>
|
||||
<dbType type="DOUBLE">
|
||||
<talendType type="id_Double" default="true"/>
|
||||
<talendType type="id_BigDecimal"/>
|
||||
<talendType type="id_Float"/>
|
||||
</dbType>
|
||||
<dbType type="DECIMAL">
|
||||
<talendType type="id_BigDecimal" default="true"/>
|
||||
</dbType>
|
||||
<dbType type="BIGINT">
|
||||
<talendType type="id_Long" default="true"/>
|
||||
<talendType type="id_Integer"/>
|
||||
</dbType>
|
||||
<dbType type="INT">
|
||||
<talendType type="id_Integer" default="true"/>
|
||||
<talendType type="id_Short"/>
|
||||
</dbType>
|
||||
<dbType type="SMALLINT">
|
||||
<talendType type="id_Short" default="true"/>
|
||||
<talendType type="id_Byte"/>
|
||||
</dbType>
|
||||
<dbType type="TINYINT">
|
||||
<talendType type="id_Byte" default="true"/>
|
||||
</dbType>
|
||||
<dbType type="FLOAT">
|
||||
<talendType type="id_Float" default="true"/>
|
||||
<talendType type="id_Double"/>
|
||||
<talendType type="id_BigDecimal"/>
|
||||
</dbType>
|
||||
<dbType type="STRUCT">
|
||||
<talendType type="id_Object" default="true"/>
|
||||
</dbType>
|
||||
<dbType type="MAP">
|
||||
<talendType type="id_Object" default="true"/>
|
||||
</dbType>
|
||||
<dbType type="ARRAY">
|
||||
<talendType type="id_Object" default="true"/>
|
||||
</dbType>
|
||||
<dbType type="TIMESTAMP">
|
||||
<talendType type="id_Date" default="true"/>
|
||||
</dbType>
|
||||
<dbType type="DATE">
|
||||
<talendType type="id_Date" default="true"/>
|
||||
</dbType>
|
||||
</dbToTalendTypes>
|
||||
</language>
|
||||
</dbms>
|
||||
</mapping>
|
||||
@@ -9,7 +9,7 @@
|
||||
<dbType type="CHAR" defaultLength="50" ignorePre="true"/>
|
||||
<dbType type="CHARACTER" ignoreLen="true" ignorePre="true" />
|
||||
<dbType type="CHARACTER VARYING" ignoreLen="true" ignorePre="true" />
|
||||
<dbType type="DATE" ignoreLen="true" ignorePre="true" />
|
||||
<dbType type="DATE" ignoreLen="true" ignorePre="true" defaultPattern="dd-MM-yyyy" />
|
||||
<dbType type="DATETIME" ignoreLen="true" ignorePre="true" />
|
||||
<dbType type="DECIMAL" defaultLength="20" defaultPrecision="10" />
|
||||
<dbType type="DOUBLE PRECISION" ignoreLen="true" ignorePre="true" />
|
||||
|
||||
@@ -100,6 +100,11 @@
|
||||
<xs:restriction base="xs:short"/>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="defaultPattern">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string"/>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="default" type="xs:boolean"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@@ -214,5 +214,5 @@ public interface ITDQRepositoryService extends IService {
|
||||
/**
|
||||
* @param chooseContext the context name which want to swtich
|
||||
*/
|
||||
void popupSwitchContextFailedMessage(String chooseContext);
|
||||
boolean popupSwitchContextFailedMessage(String chooseContext);
|
||||
}
|
||||
|
||||
@@ -230,10 +230,10 @@ public enum EDatabaseTypeName {
|
||||
return getTypeFromDispalyNameOriginal(dbType);
|
||||
}
|
||||
for (EDatabaseTypeName typename : EDatabaseTypeName.values()) {
|
||||
if (typename.getXmlName().toUpperCase().equals(dbType.toUpperCase())) {
|
||||
if (typename.getXmlName().equalsIgnoreCase(dbType)) {
|
||||
return typename;
|
||||
}
|
||||
if (typename.getProduct().toUpperCase().equals(dbType.toUpperCase())) {
|
||||
if (typename.getProduct().equalsIgnoreCase(dbType)) {
|
||||
return typename;
|
||||
}
|
||||
}
|
||||
@@ -245,10 +245,10 @@ public enum EDatabaseTypeName {
|
||||
return getTypeFromDisplayNameOriginal(dbType, isDefault);
|
||||
}
|
||||
for (EDatabaseTypeName typename : EDatabaseTypeName.values()) {
|
||||
if (typename.getXmlName().toUpperCase().equals(dbType.toUpperCase())) {
|
||||
if (typename.getXmlName().equalsIgnoreCase(dbType)) {
|
||||
return typename;
|
||||
}
|
||||
if (typename.getProduct().toUpperCase().equals(dbType.toUpperCase())) {
|
||||
if (typename.getProduct().equalsIgnoreCase(dbType)) {
|
||||
return typename;
|
||||
}
|
||||
}
|
||||
@@ -264,7 +264,7 @@ public enum EDatabaseTypeName {
|
||||
return MYSQL;
|
||||
}
|
||||
for (EDatabaseTypeName typename : EDatabaseTypeName.values()) {
|
||||
if (typename.getDisplayName().toLowerCase().equals(displayName.toLowerCase())) {
|
||||
if (typename.getDisplayName().equalsIgnoreCase(displayName)) {
|
||||
return typename;
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public enum EDatabaseTypeName {
|
||||
return null;
|
||||
}
|
||||
for (EDatabaseTypeName typename : EDatabaseTypeName.values()) {
|
||||
if (typename.getDisplayName().toLowerCase().equals(displayName.toLowerCase())) {
|
||||
if (typename.getDisplayName().equalsIgnoreCase(displayName)) {
|
||||
return typename;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,12 +102,12 @@ public enum EDatabaseVersion4Drivers {
|
||||
|
||||
GREENPLUM(new DbVersion4Drivers(EDatabaseTypeName.GREENPLUM, "postgresql-8.4-703.jdbc4.jar")), //$NON-NLS-1$
|
||||
// PSQL_V10(new DbVersion4Drivers(EDatabaseTypeName.PSQL, "v10", "V10", "postgresql-42.2.5.jar")),
|
||||
PSQL_V9_X(new DbVersion4Drivers(EDatabaseTypeName.PSQL, "v9 and later", "V9_X", "postgresql-42.2.9.jar")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
PSQL_V9_X(new DbVersion4Drivers(EDatabaseTypeName.PSQL, "v9 and later", "V9_X", "postgresql-42.2.14.jar")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
PSQL_PRIOR_TO_V9(new DbVersion4Drivers(EDatabaseTypeName.PSQL, "Prior to v9", "PRIOR_TO_V9", "postgresql-8.4-703.jdbc4.jar")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
PLUSPSQL_PRIOR_TO_V9(new DbVersion4Drivers(EDatabaseTypeName.PLUSPSQL,
|
||||
"Prior to v9", "PRIOR_TO_V9", "postgresql-8.4-703.jdbc4.jar")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
PLUSPSQL_V9_X(new DbVersion4Drivers(EDatabaseTypeName.PLUSPSQL, "v9 and later", "V9_X", "postgresql-9.4-1201.jdbc41.jar")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
PLUSPSQL_V9_X(new DbVersion4Drivers(EDatabaseTypeName.PLUSPSQL, "v9 and later", "V9_X", "postgresql-42.2.14.jar")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
IBMDB2(new DbVersion4Drivers(EDatabaseTypeName.IBMDB2, new String[] { "db2jcc4.jar", "db2jcc_license_cu.jar", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
"db2jcc_license_cisuz.jar" })), //$NON-NLS-1$
|
||||
IBMDB2ZOS(new DbVersion4Drivers(EDatabaseTypeName.IBMDB2ZOS, new String[] { "db2jcc4.jar", "db2jcc_license_cu.jar", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
@@ -166,7 +166,7 @@ public enum EDatabaseVersion4Drivers {
|
||||
REDSHIFT(new DbVersion4Drivers(EDatabaseTypeName.REDSHIFT, "redshift", "REDSHIFT", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
"redshift-jdbc42-no-awssdk-1.2.37.1061.jar")), //$NON-NLS-1$
|
||||
REDSHIFT_SSO(new DbVersion4Drivers(EDatabaseTypeName.REDSHIFT_SSO, "redshift sso", "REDSHIFT_SSO", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
new String[] { "redshift-jdbc42-no-awssdk-1.2.37.1061.jar", "aws-java-sdk-1.11.729.jar", "jackson-core-2.10.1.jar", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
new String[] { "redshift-jdbc42-no-awssdk-1.2.37.1061.jar", "aws-java-sdk-1.11.848.jar", "jackson-core-2.10.1.jar", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"jackson-databind-2.10.1.jar", "jackson-annotations-2.10.1.jar", "httpcore-4.4.11.jar", "httpclient-4.5.9.jar", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
|
||||
"joda-time-2.8.1.jar", "commons-logging-1.2.jar", "commons-codec-1.11.jar" })), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// ============================================================================
|
||||
package org.talend.core.model.context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -47,12 +48,14 @@ import org.talend.core.model.properties.ContextItem;
|
||||
import org.talend.core.model.properties.Item;
|
||||
import org.talend.core.model.properties.JobletProcessItem;
|
||||
import org.talend.core.model.properties.ProcessItem;
|
||||
import org.talend.core.model.repository.ERepositoryObjectType;
|
||||
import org.talend.core.model.repository.IRepositoryViewObject;
|
||||
import org.talend.core.runtime.CoreRuntimePlugin;
|
||||
import org.talend.cwm.helper.ResourceHelper;
|
||||
import org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType;
|
||||
import org.talend.designer.core.model.utils.emf.talendfile.ContextType;
|
||||
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
|
||||
import org.talend.migration.IMigrationTask.ExecutionResult;
|
||||
import org.talend.repository.model.IProxyRepositoryFactory;
|
||||
|
||||
/**
|
||||
@@ -68,6 +71,7 @@ public class ContextUtils {
|
||||
"instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", "final", "interface", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$
|
||||
"static", "void", "class", "finally", "long", "strictfp", "volatile", "const", "float", "native", "super", "while")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* ggu Comment method "isJavaKeyWords".
|
||||
@@ -166,10 +170,10 @@ public class ContextUtils {
|
||||
ContextType defaultContextType = null;
|
||||
for (ContextType type : contextTypeList) {
|
||||
// Modified by Marvin Wang on Jun. 21, 2012 for bug TDI-21009. To avoid case sensitive.
|
||||
if (contextName != null && type.getName() != null && type.getName().toLowerCase().equals(contextName.toLowerCase())) {
|
||||
if (contextName != null && type.getName() != null && type.getName().equalsIgnoreCase(contextName)) {
|
||||
contextType = type;
|
||||
} else if (defaultContextName != null && type.getName() != null
|
||||
&& type.getName().toLowerCase().equals(defaultContextName.toLowerCase())) {
|
||||
&& type.getName().equalsIgnoreCase(defaultContextName)) {
|
||||
defaultContextType = type;
|
||||
}
|
||||
}
|
||||
@@ -222,7 +226,6 @@ public class ContextUtils {
|
||||
return parameterType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static boolean checkObject(Object obj) {
|
||||
if (obj == null) {
|
||||
return true;
|
||||
@@ -269,7 +272,7 @@ public class ContextUtils {
|
||||
|
||||
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
|
||||
try {
|
||||
final IRepositoryViewObject lastVersion = factory.getLastVersion(contextId);
|
||||
final IRepositoryViewObject lastVersion = factory.getLastVersion(contextId, ERepositoryObjectType.CONTEXT);
|
||||
if (lastVersion != null) {
|
||||
final Item item = lastVersion.getProperty().getItem();
|
||||
if (item != null && item instanceof ContextItem) {
|
||||
@@ -486,9 +489,13 @@ public class ContextUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
|
||||
List<ERepositoryObjectType> possibleTypes = new ArrayList<ERepositoryObjectType>();
|
||||
possibleTypes.add(ERepositoryObjectType.CONTEXT);
|
||||
possibleTypes.addAll(ERepositoryObjectType.getAllTypesOfJoblet());
|
||||
possibleTypes.addAll(ERepositoryObjectType.getAllTypesOfProcess());
|
||||
try {
|
||||
final IRepositoryViewObject lastVersion = factory.getLastVersion(contextId);
|
||||
IRepositoryViewObject lastVersion = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory()
|
||||
.getLastVersion(contextId, possibleTypes);
|
||||
if (lastVersion != null) {
|
||||
final Item item = lastVersion.getProperty().getItem();
|
||||
if (item != null) {
|
||||
@@ -582,7 +589,8 @@ public class ContextUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
// preference name must match TalendDesignerPrefConstants.PROPAGATE_CONTEXT_VARIABLE
|
||||
// preference name must match
|
||||
// TalendDesignerPrefConstants.PROPAGATE_CONTEXT_VARIABLE
|
||||
return Boolean.parseBoolean(
|
||||
CoreRuntimePlugin.getInstance().getDesignerCoreService().getPreferenceStore("propagateContextVariable")); //$NON-NLS-1$
|
||||
}
|
||||
@@ -1037,4 +1045,70 @@ public class ContextUtils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ExecutionResult doCreateContextLinkMigration(Item item) {
|
||||
IProxyRepositoryFactory proxyRepositoryFactory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
|
||||
boolean modified = false, hasLinkFile = false;
|
||||
try {
|
||||
List<ContextType> contextTypeList = ContextUtils.getAllContextType(item);
|
||||
if (contextTypeList != null && contextTypeList.size() > 0) {
|
||||
for (ContextType contextType : contextTypeList) {
|
||||
for (Object obj : contextType.getContextParameter()) {
|
||||
if (obj instanceof ContextParameterType) {
|
||||
ContextParameterType paramType = (ContextParameterType) obj;
|
||||
if (ContextUtils.isBuildInParameter(paramType)) {
|
||||
if (StringUtils.isEmpty(paramType.getInternalId())) {
|
||||
paramType.setInternalId(proxyRepositoryFactory.getNextId());
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
hasLinkFile = ContextLinkService.getInstance().saveContextLink(item);
|
||||
} catch (Exception ex) {
|
||||
ExceptionHandler.process(ex);
|
||||
return ExecutionResult.FAILURE;
|
||||
}
|
||||
if (modified || hasLinkFile) {
|
||||
try {
|
||||
if (modified) {
|
||||
proxyRepositoryFactory.save(item, true);
|
||||
}
|
||||
return ExecutionResult.SUCCESS_NO_ALERT;
|
||||
} catch (Exception ex) {
|
||||
ExceptionHandler.process(ex);
|
||||
return ExecutionResult.FAILURE;
|
||||
}
|
||||
}
|
||||
return ExecutionResult.NOTHING_TO_DO;
|
||||
}
|
||||
|
||||
public static ExecutionResult doCreateContextLinkMigration(ERepositoryObjectType repositoryType, Item item) {
|
||||
if (item != null && getAllSupportContextLinkTypes().contains(repositoryType)) {
|
||||
return doCreateContextLinkMigration(item);
|
||||
}
|
||||
return ExecutionResult.NOTHING_TO_DO;
|
||||
}
|
||||
|
||||
public static List<ERepositoryObjectType> getAllSupportContextLinkTypes() {
|
||||
List<ERepositoryObjectType> toReturn = new ArrayList<ERepositoryObjectType>();
|
||||
toReturn.addAll(ERepositoryObjectType.getAllTypesOfProcess());
|
||||
toReturn.addAll(ERepositoryObjectType.getAllTypesOfProcess2());
|
||||
toReturn.addAll(ERepositoryObjectType.getAllTypesOfTestContainer());
|
||||
toReturn.addAll(getAllMetaDataType());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private static List<ERepositoryObjectType> getAllMetaDataType() {
|
||||
List<ERepositoryObjectType> list = new ArrayList<ERepositoryObjectType>();
|
||||
ERepositoryObjectType[] allTypes = (ERepositoryObjectType[]) ERepositoryObjectType.values();
|
||||
for (ERepositoryObjectType object : allTypes) {
|
||||
if (object.isChildTypeOf(ERepositoryObjectType.METADATA)) {
|
||||
list.add(object);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,13 +224,13 @@ public class JobContextManager implements IContextManager {
|
||||
if (oldContextName != null) {
|
||||
if (!oldContextName.equals(contextParameter.getName())) {
|
||||
if (contextParameter.getName().equals(newContextName)
|
||||
|| contextParameter.getName().toLowerCase().equals(newContextName.toLowerCase())) {
|
||||
|| contextParameter.getName().equalsIgnoreCase(newContextName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (contextParameter.getName().equals(newContextName)
|
||||
|| contextParameter.getName().toLowerCase().equals(newContextName.toLowerCase())) {
|
||||
|| contextParameter.getName().equalsIgnoreCase(newContextName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,15 +18,18 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.commons.exception.PersistenceException;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.model.context.ContextUtils;
|
||||
import org.talend.core.model.properties.ContextItem;
|
||||
import org.talend.core.model.properties.Item;
|
||||
import org.talend.core.runtime.CoreRuntimePlugin;
|
||||
import org.talend.cwm.helper.ResourceHelper;
|
||||
import org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType;
|
||||
import org.talend.designer.core.model.utils.emf.talendfile.ContextType;
|
||||
import org.talend.repository.ProjectManager;
|
||||
import org.talend.repository.model.IRepositoryService;
|
||||
|
||||
|
||||
@@ -106,16 +109,26 @@ public abstract class AbstractItemContextLinkService implements IItemContextLink
|
||||
}
|
||||
|
||||
Item contextItem = tempCache.get(repositoryContextId);
|
||||
IRepositoryService repositoryService = GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
|
||||
if (contextItem == null) {
|
||||
contextItem = ContextUtils.getRepositoryContextItemById(repositoryContextId);
|
||||
tempCache.put(repositoryContextId, contextItem);
|
||||
if (contextItem != null && !(contextItem instanceof ContextItem)
|
||||
&& ProjectManager.getInstance().isInCurrentMainProject(contextItem)
|
||||
&& checkRepoItemContextParamInternalId(contextItem)) {
|
||||
try {
|
||||
repositoryService.getProxyRepositoryFactory().save(contextItem, true); // This should only using for migration phase // case the internal id is null
|
||||
} catch (Exception ex) {
|
||||
ExceptionHandler.process(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (contextItem != null) {
|
||||
ContextType contextType = ContextUtils.getContextTypeByName(contextItem, contextName);
|
||||
ContextParameterType repoContextParameterType = ContextUtils.getContextParameterTypeByName(contextType, paramName);
|
||||
if (repoContextParameterType != null && repoContextParameterType.eResource() == null) {
|
||||
// processItem save before than contextItem, caused eResource null
|
||||
IRepositoryService repositoryService = GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
|
||||
|
||||
try {
|
||||
repositoryService.getProxyRepositoryFactory().save(contextItem, false);
|
||||
} catch (PersistenceException e) {
|
||||
@@ -170,6 +183,30 @@ public abstract class AbstractItemContextLinkService implements IItemContextLink
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean checkRepoItemContextParamInternalId(Item item) {
|
||||
boolean isModified = false;
|
||||
EList<?> contextTypeList = ContextUtils.getAllContextType(item);
|
||||
if (contextTypeList != null) {
|
||||
for (Object typeObj : contextTypeList) {
|
||||
if (typeObj instanceof ContextType) {
|
||||
ContextType type = (ContextType) typeObj;
|
||||
for (Object obj : type.getContextParameter()) {
|
||||
if (obj instanceof ContextParameterType) {
|
||||
ContextParameterType contextParam = (ContextParameterType) obj;
|
||||
if (ContextUtils.isBuildInParameter(contextParam)
|
||||
&& StringUtils.isEmpty(contextParam.getInternalId())) {
|
||||
contextParam
|
||||
.setInternalId(CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().getNextId());
|
||||
isModified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return isModified;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -119,6 +119,8 @@ public interface ILibrariesService extends IService {
|
||||
List<ModuleNeeded> getModuleNeeded(String id, boolean isGroup);
|
||||
|
||||
public void deployProjectLibrary(File source) throws IOException;
|
||||
|
||||
public void setForceReloadCustomUri();
|
||||
|
||||
/**
|
||||
* Listener used to fire that libraries status has been changed (new lib or new check install).
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.talend.core.model.metadata;
|
||||
|
||||
public class DbDefaultDatePattern {
|
||||
private String defaultPattern;
|
||||
private String dbTypeName;
|
||||
|
||||
public DbDefaultDatePattern() {
|
||||
|
||||
}
|
||||
|
||||
public String getDefaultPattern() {
|
||||
return defaultPattern;
|
||||
}
|
||||
|
||||
public void setDefaultPattern(String defaultPattern) {
|
||||
this.defaultPattern = defaultPattern;
|
||||
}
|
||||
|
||||
public String getDbTypeName() {
|
||||
return dbTypeName;
|
||||
}
|
||||
|
||||
public void setDbTypeName(String dbTypeName) {
|
||||
this.dbTypeName = dbTypeName;
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,8 @@ public class Dbms {
|
||||
private Set<MappingType> talendToDbTypes;
|
||||
|
||||
private List<DbDefaultLengthAndPrecision> defaultLengthPrecision;
|
||||
|
||||
private List<DbDefaultDatePattern> defaultPattern;
|
||||
|
||||
private List<DbIgnoreLengthAndPrecision> ignoreLengthPrecision;
|
||||
|
||||
@@ -62,6 +64,14 @@ public class Dbms {
|
||||
List<DbDefaultLengthAndPrecision> defaultLengthPrecision) {
|
||||
this.defaultLengthPrecision = defaultLengthPrecision;
|
||||
}
|
||||
public List<DbDefaultDatePattern> getDefaultPattern() {
|
||||
return defaultPattern;
|
||||
}
|
||||
|
||||
public void setDefaultPattern(
|
||||
List<DbDefaultDatePattern> defaultLengthPrecision) {
|
||||
this.defaultPattern = defaultLengthPrecision;
|
||||
}
|
||||
|
||||
/**
|
||||
* DOC amaumont Dbms constructor comment.
|
||||
|
||||
@@ -125,10 +125,12 @@ public class MappingFileLoader {
|
||||
// search and load preBeforelen nodes
|
||||
ArrayList<String> dbTypes = new ArrayList<String>();
|
||||
ArrayList<DbDefaultLengthAndPrecision> dbDefault = new ArrayList<DbDefaultLengthAndPrecision>();
|
||||
ArrayList<DbDefaultDatePattern> dbDefaultPattern = new ArrayList<DbDefaultDatePattern>();
|
||||
ArrayList<DbIgnoreLengthAndPrecision> dbIgnore = new ArrayList<DbIgnoreLengthAndPrecision>();
|
||||
ArrayList<DbPreBeforeLength> dbPbeforeLList = new ArrayList<DbPreBeforeLength>();
|
||||
dbms.setDbmsTypes(dbTypes);
|
||||
dbms.setDefaultLengthPrecision(dbDefault);
|
||||
dbms.setDefaultPattern(dbDefaultPattern);
|
||||
dbms.setIgnoreLengthPrecision(dbIgnore);
|
||||
dbms.setPrebeforelength(dbPbeforeLList);
|
||||
List<Node> typeNodes = getChildElementNodes(dbTypesNode);
|
||||
@@ -149,19 +151,25 @@ public class MappingFileLoader {
|
||||
dbTypes.add(typeValue);
|
||||
hAllDbTypes.add(typeValue);
|
||||
DbDefaultLengthAndPrecision dbDefaultLP = new DbDefaultLengthAndPrecision();
|
||||
DbDefaultDatePattern dbDefaultPt = new DbDefaultDatePattern();
|
||||
DbIgnoreLengthAndPrecision dbIgnoreLP = new DbIgnoreLengthAndPrecision();
|
||||
DbPreBeforeLength dbPBeforeL = new DbPreBeforeLength();
|
||||
// default length and precision
|
||||
Node defaultLengthItem = typeNodeAtttributes.getNamedItem("defaultLength"); //$NON-NLS-1$
|
||||
Node defaultPrecision = typeNodeAtttributes.getNamedItem("defaultPrecision"); //$NON-NLS-1$
|
||||
Node defaultPattern = typeNodeAtttributes.getNamedItem("defaultPattern"); //$NON-NLS-1$
|
||||
|
||||
if (defaultLengthItem != null)
|
||||
dbDefaultLP.setDefaultLength(Integer.parseInt(defaultLengthItem.getNodeValue()));
|
||||
if (defaultPrecision != null)
|
||||
dbDefaultLP.setDefaultPrecision(Integer.parseInt(defaultPrecision.getNodeValue()));
|
||||
if (defaultPattern != null)
|
||||
dbDefaultPt.setDefaultPattern(defaultPattern.getNodeValue());
|
||||
|
||||
dbDefaultLP.setDbTypeName(typeValue);
|
||||
dbDefaultPt.setDbTypeName(typeValue);
|
||||
dbDefault.add(dbDefaultLP);
|
||||
dbDefaultPattern.add(dbDefaultPt);
|
||||
|
||||
// ignore Length and Precision
|
||||
Node ignoreLength = typeNodeAtttributes.getNamedItem("ignoreLen"); //$NON-NLS-1$
|
||||
|
||||
@@ -191,6 +191,24 @@ public class MappingTypeRetriever {
|
||||
}// end for
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDefaultPattern(String dbmsId, String dbType) {
|
||||
Dbms dbms = MetadataTalendType.getDbms(dbmsId);
|
||||
List<DbDefaultDatePattern> defaultPattern = dbms.getDefaultPattern();
|
||||
String pattern = new String(""); //$NON-NLS-1$
|
||||
for (int i = 0; i < defaultPattern.size(); i++) {
|
||||
DbDefaultDatePattern dbPattern = (DbDefaultDatePattern) defaultPattern.get(i);
|
||||
if (dbPattern.getDbTypeName().equalsIgnoreCase(dbType)) {
|
||||
pattern = dbPattern.getDefaultPattern();
|
||||
if (pattern == null) {
|
||||
return "";
|
||||
} else {
|
||||
return pattern;
|
||||
}
|
||||
}// end if
|
||||
}// end for
|
||||
return pattern;
|
||||
}
|
||||
|
||||
private boolean isExtensionPrecisionIgnored(String dbmsId, String dbType) {
|
||||
Map<String, Map<String, List<DBTypeUtil>>> javaTypeMappingFromExtension = JavaTypesManager
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
package org.talend.core.model.metadata;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@@ -31,8 +32,11 @@ import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
@@ -488,6 +492,42 @@ public final class MetadataTalendType {
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncNewMappingFileToProject() throws SystemException {
|
||||
try {
|
||||
File sysMappingFiles = new File(MetadataTalendType.getSystemForderURLOfMappingsFile().getPath());
|
||||
IFolder projectMappingFolder = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject())
|
||||
.getFolder(MetadataTalendType.PROJECT_MAPPING_FOLDER);
|
||||
File projectMappingFiles = projectMappingFolder.getFullPath().toFile();
|
||||
if (sysMappingFiles.list().length == new File(projectMappingFolder.getLocationURI()).list().length) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (File sysMapping : sysMappingFiles.listFiles()) {
|
||||
IFile projectMapping = projectMappingFolder.getFile(sysMapping.getName());
|
||||
if (!projectMapping.exists()) {
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(sysMapping);
|
||||
projectMapping.create(fis, true, null);
|
||||
} catch (CoreException coreExc) {
|
||||
throw new SystemException(coreExc);
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException ioExc) {
|
||||
throw new SystemException(ioExc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new SystemException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Load db types and mapping with the current activated language (Java, Perl, ...).
|
||||
|
||||
@@ -779,7 +779,7 @@ public final class MetadataToolHelper {
|
||||
for (IMetadataColumn inputColumn : sourceColumns) {
|
||||
for (IMetadataColumn outputcolumn : target.getListColumns()) {
|
||||
String outputColumnName = outputcolumn.getLabel();
|
||||
if (inputColumn.getLabel().toLowerCase().equals(("" + outputColumnName).toLowerCase())) {
|
||||
if (inputColumn.getLabel().equalsIgnoreCase("" + outputColumnName)) {
|
||||
columnsToRemoveMap.put(inputColumn, outputColumnName);
|
||||
}
|
||||
if (outputcolumn.isReadOnly()) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
@@ -71,6 +72,7 @@ import org.talend.core.model.utils.ContextParameterUtils;
|
||||
import org.talend.core.model.utils.IDragAndDropServiceHandler;
|
||||
import org.talend.core.runtime.i18n.Messages;
|
||||
import org.talend.core.runtime.services.IGenericDBService;
|
||||
import org.talend.core.runtime.services.IGenericWizardService;
|
||||
import org.talend.core.utils.TalendQuoteUtils;
|
||||
import org.talend.cwm.helper.ConnectionHelper;
|
||||
import org.talend.cwm.helper.PackageHelper;
|
||||
@@ -366,6 +368,21 @@ public class ComponentToRepositoryProperty {
|
||||
if (para.getRepositoryValue().endsWith(EDatabaseTypeName.GENERAL_JDBC.getProduct())) {
|
||||
connection.setDatabaseType(EDatabaseTypeName.GENERAL_JDBC.getProduct());
|
||||
connection.setProductId(EDatabaseTypeName.GENERAL_JDBC.getProduct());
|
||||
if (!node.getComponent().getDisplayName().equals(node.getComponent().getName())) {
|
||||
// additional JDBC e.g. Delta Lake
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
|
||||
IGenericWizardService service = GlobalServiceRegister.getDefault()
|
||||
.getService(IGenericWizardService.class);
|
||||
if (service != null) {
|
||||
String database = service.getDatabseNameByNode(node);
|
||||
if (StringUtils.isNotBlank(database)) {
|
||||
connection.setProductId(database);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// vertica output component have no TYPE ElementParameter .
|
||||
if (para.getRepositoryValue().endsWith(EDatabaseTypeName.VERTICA.getProduct())) {
|
||||
|
||||
@@ -813,13 +813,7 @@ public class RepositoryToComponentProperty {
|
||||
* @return
|
||||
*/
|
||||
private static Object getMDMValue(MDMConnection connection, String value, IMetadataTable table) {
|
||||
if ("MDM_VERSION".equals(value)) {//$NON-NLS-1$
|
||||
if (connection.getVersion() == null || "".equals(connection.getVersion())) {
|
||||
return MDMVersions.MDM_S56.getKey();
|
||||
} else {
|
||||
return connection.getVersion();
|
||||
}
|
||||
} else if ("MDMURL".equals(value)) { //$NON-NLS-1$
|
||||
if ("MDMURL".equals(value)) { //$NON-NLS-1$
|
||||
if (isContextMode(connection, connection.getServerUrl())) {
|
||||
return connection.getServerUrl();
|
||||
} else {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
package org.talend.core.model.process;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -368,4 +369,38 @@ public class BigDataNode extends AbstractNode implements IBigDataNode {
|
||||
public void processDatasetConditions(){
|
||||
// BigDataNode does not do anything related to Dataset, only anabled from SparkNode
|
||||
}
|
||||
|
||||
public List<? extends IConnection> getIncomingConnections(EConnectionType... connectionTypes) {
|
||||
List<IConnection> conns = null;
|
||||
List<EConnectionType> types = Arrays.asList(connectionTypes);
|
||||
List<? extends IConnection> incomingConnections = this.getIncomingConnections();
|
||||
if (incomingConnections != null) {
|
||||
conns = new ArrayList<IConnection>();
|
||||
|
||||
for (int i = 0; i < incomingConnections.size(); i++) {
|
||||
IConnection connection = incomingConnections.get(i);
|
||||
if (types.contains(connection.getLineStyle())) {
|
||||
conns.add(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
return conns;
|
||||
}
|
||||
|
||||
public List<? extends IConnection> getOutgoingConnections(EConnectionType... connectionTypes) {
|
||||
List<IConnection> conns = null;
|
||||
List<EConnectionType> types = Arrays.asList(connectionTypes);
|
||||
List<? extends IConnection> incomingConnections = this.getOutgoingConnections();
|
||||
if (incomingConnections != null) {
|
||||
conns = new ArrayList<IConnection>();
|
||||
|
||||
for (int i = 0; i < incomingConnections.size(); i++) {
|
||||
IConnection connection = incomingConnections.get(i);
|
||||
if (types.contains(connection.getLineStyle())) {
|
||||
conns.add(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
return conns;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,5 +141,19 @@ public interface IBigDataNode extends INode {
|
||||
* Loading and processing should be separated because conditions can be dependent on future component (in subjob order)
|
||||
*/
|
||||
public void processDatasetConditions();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param connectionTypes
|
||||
* @return connections according to multiple EConnectionType
|
||||
*/
|
||||
public List<? extends IConnection> getIncomingConnections(EConnectionType... connectionTypes);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param connectionTypes
|
||||
* @return connections according to multiple EConnectionType
|
||||
*/
|
||||
public List<? extends IConnection> getOutgoingConnections(EConnectionType... connectionTypes);
|
||||
|
||||
}
|
||||
|
||||
@@ -1003,4 +1003,12 @@ public final class ProcessUtils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isChildRouteProcess(IProcess process) {
|
||||
List n = process.getNodesOfType("tRouteInput");
|
||||
if (n!=null && n.size()!=0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.talend.designer.core.model.utils.emf.talendfile.NodeType;
|
||||
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
|
||||
import org.talend.repository.ProjectManager;
|
||||
import org.talend.repository.model.IProxyRepositoryFactory;
|
||||
import org.talend.repository.model.IRepositoryNode;
|
||||
|
||||
/**
|
||||
* This class store all relationships between jobs/joblets and other items from the repository. Be sure to update the
|
||||
@@ -223,9 +224,9 @@ public class RelationshipItemBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Current System Routines Map, key: routine id, value: routine name
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> getCurrentSystemRoutinesMap() {
|
||||
@@ -929,7 +930,10 @@ public class RelationshipItemBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private void addRelationShip(Item baseItem, String relatedId, String relatedVersion, String type) {
|
||||
public void addRelationShip(Item baseItem, String relatedId, String relatedVersion, String type) {
|
||||
if (!loaded) {
|
||||
loadRelations();
|
||||
}
|
||||
Relation relation = new Relation();
|
||||
relation.setId(baseItem.getProperty().getId());
|
||||
relation.setType(getTypeFromItem(baseItem));
|
||||
@@ -945,6 +949,30 @@ public class RelationshipItemBuilder {
|
||||
itemRelations.put(relation, new HashSet<Relation>());
|
||||
}
|
||||
itemRelations.get(relation).add(addedRelation);
|
||||
|
||||
autoSaveRelations();
|
||||
}
|
||||
|
||||
public Set<Relation> getBeanRelations(Collection<Item> items) {
|
||||
Set<Relation> relationships = new HashSet<Relation>();
|
||||
for (Item item : items) {
|
||||
Relation relation = new Relation();
|
||||
relation.setId(item.getProperty().getId());
|
||||
relation.setType(getTypeFromItem(item));
|
||||
relation.setVersion(item.getProperty().getVersion());
|
||||
|
||||
Map<Relation, Set<Relation>> itemRelations = getRelatedRelations(item);
|
||||
|
||||
Set<Relation> repositoryNode = (Set<Relation>) itemRelations.get(relation);
|
||||
|
||||
for (Relation rel : repositoryNode) {
|
||||
if (rel.getType().equals("Beans")) {
|
||||
relationships.add(rel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return relationships;
|
||||
}
|
||||
|
||||
private Map<Relation, Set<Relation>> getRelatedRelations(Item baseItem) {
|
||||
|
||||
@@ -46,7 +46,11 @@ import org.talend.core.model.process.IElementParameter;
|
||||
import org.talend.core.model.process.INode;
|
||||
import org.talend.core.model.process.INodeConnector;
|
||||
import org.talend.core.model.process.IProcess;
|
||||
import org.talend.core.model.process.IProcess2;
|
||||
import org.talend.core.model.process.ProcessUtils;
|
||||
import org.talend.core.model.properties.Property;
|
||||
import org.talend.core.runtime.IAdditionalInfo;
|
||||
import org.talend.core.runtime.projectsetting.RuntimeLineageManager;
|
||||
import org.talend.designer.core.ICamelDesignerCoreService;
|
||||
|
||||
/**
|
||||
@@ -866,6 +870,170 @@ public class NodeUtil {
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
|
||||
public static String getRuntimeParameterValue(INode node, IElementParameter ep) {
|
||||
if (EParameterFieldType.TABLE.equals(ep.getFieldType())) {
|
||||
Map<String, IElementParameter> types = new HashMap<String, IElementParameter>();
|
||||
Object[] itemsValue = ep.getListItemsValue();
|
||||
if (itemsValue != null) {
|
||||
for (Object o : itemsValue) {
|
||||
IElementParameter cep = (IElementParameter) o;
|
||||
if (cep.isShow(node.getElementParameters())) {
|
||||
types.put(cep.getName(), cep);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Map<String, String>> lines = (List<Map<String, String>>) ElementParameterParser.getObjectValue(node,
|
||||
"__" + ep.getName() + "__");
|
||||
StringBuilder value = new StringBuilder();
|
||||
// implement List & Map toString(), different is the value of Map
|
||||
Iterator<Map<String, String>> linesIter = lines.iterator();
|
||||
if (!linesIter.hasNext()) {
|
||||
return "\"[]\"";
|
||||
}
|
||||
value.append("new StringBuilder().append(\"[");
|
||||
for (;;) {
|
||||
Map<String, String> columns = linesIter.next();
|
||||
Iterator<Entry<String, String>> columnsIter = columns.entrySet().iterator();
|
||||
|
||||
value.append("{");
|
||||
Entry<String, String> column = null;
|
||||
boolean printedColumnExist = false;
|
||||
while (columnsIter.hasNext()) {
|
||||
column = columnsIter.next();
|
||||
if (types.get(column.getKey()) == null) {
|
||||
continue;
|
||||
}
|
||||
printedColumnExist = true;
|
||||
|
||||
value.append(column.getKey());
|
||||
value.append("=\").append(");
|
||||
value.append(getRuntimeParameterValue(column.getValue(), types.get(column.getKey()), true));
|
||||
value.append(").append(\"");
|
||||
|
||||
if (columnsIter.hasNext()) {
|
||||
value.append(", ");
|
||||
}
|
||||
}
|
||||
if (printedColumnExist && column != null && (types.get(column.getKey()) == null)) {
|
||||
value.setLength(value.length() - 2);
|
||||
}
|
||||
value.append("}");
|
||||
|
||||
if (!linesIter.hasNext()) {
|
||||
return value.append("]\").toString()").toString();
|
||||
}
|
||||
value.append(",").append(" ");
|
||||
}
|
||||
} else {
|
||||
String value = ElementParameterParser.getValue(node, "__" + ep.getName() + "__");
|
||||
if (EParameterFieldType.TABLE_BY_ROW.equals(ep.getFieldType())) {
|
||||
value = ep.getValue().toString();
|
||||
}
|
||||
return getRuntimeParameterValue(value, ep, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getRuntimeParameterValue(String value, IElementParameter ep, boolean itemFromTable) {
|
||||
if (value == null) {
|
||||
value = "";
|
||||
}
|
||||
|
||||
value = value.trim();
|
||||
|
||||
boolean isMemo = false;
|
||||
|
||||
List<EParameterFieldType> needRemoveCRLFList = Arrays.asList(EParameterFieldType.MEMO, EParameterFieldType.MEMO_JAVA,
|
||||
EParameterFieldType.MEMO_SQL, EParameterFieldType.MEMO_IMPORT, EParameterFieldType.MEMO_MESSAGE);
|
||||
if (needRemoveCRLFList.contains(ep.getFieldType())) {
|
||||
isMemo = true;
|
||||
value = value.replaceAll("[\r\n]", " ");
|
||||
}
|
||||
|
||||
List<EParameterFieldType> needQuoteList = Arrays.asList(EParameterFieldType.CLOSED_LIST,
|
||||
EParameterFieldType.COMPONENT_LIST, EParameterFieldType.COLUMN_LIST, EParameterFieldType.PREV_COLUMN_LIST,
|
||||
EParameterFieldType.CONNECTION_LIST, EParameterFieldType.LOOKUP_COLUMN_LIST,
|
||||
EParameterFieldType.CONTEXT_PARAM_NAME_LIST, EParameterFieldType.PROCESS_TYPE, EParameterFieldType.COLOR,
|
||||
EParameterFieldType.TABLE_BY_ROW, EParameterFieldType.HADOOP_JARS_DIALOG, EParameterFieldType.UNIFIED_COMPONENTS);
|
||||
List<EParameterFieldType> needQuoteListForItem = itemFromTable ? Arrays.asList(EParameterFieldType.SCHEMA_TYPE,
|
||||
EParameterFieldType.SAP_SCHEMA_TYPE, EParameterFieldType.MODULE_LIST) : new ArrayList<EParameterFieldType>();
|
||||
// TODO: add RAW attribute when SCHEMA_COLUMN generated by BASED_ON_SCHEMA
|
||||
List<String> needQuoteListByName = Arrays.asList("SCHEMA_COLUMN");// SCHEMA_COLUMN for BASED_ON_SCHEMA="true"
|
||||
|
||||
if (needQuoteList.contains(ep.getFieldType()) || needQuoteListForItem.contains(ep.getFieldType())
|
||||
|| needQuoteListByName.contains(ep.getName()) || ep.isRaw()) {
|
||||
value = value.replaceAll("\\\\", "\\\\\\\\");
|
||||
value = value.replaceAll("\\\"", "\\\\\\\"");
|
||||
return "\"" + value + "\"";
|
||||
}
|
||||
|
||||
if (itemFromTable) {
|
||||
if ("*".equals(value)) {
|
||||
return "\"" + value + "\"";
|
||||
}
|
||||
if (value.endsWith(";")) {
|
||||
value = value.substring(0, value.length() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if("".equals(value) || "\"\"".equals(value)) {
|
||||
return "\"\"";
|
||||
} else if("null".equals(value)) {
|
||||
return "(Object)null";
|
||||
}
|
||||
|
||||
// copied it from Log4jFileUtil.javajet but need more comment for this script
|
||||
if ("\"\\n\"".equals(value) || "\"\\r\"".equals(value) || "\"\\r\\n\"".equals(value)) {
|
||||
// for the value is "\n" "\r" "\r\n"
|
||||
return value.replaceAll("\\\\", "\\\\\\\\");
|
||||
} else if ("\"\"\"".equals(value)) {
|
||||
return "\"" + "\\" + "\"" + "\"";
|
||||
} else if ("\"\"\\r\\n\"\"".equals(value)) {
|
||||
return "\"\\\\r\\\\n\"";
|
||||
} else if ("\"\"\\r\"\"".equals(value)) {
|
||||
return "\"\\\\r\"";
|
||||
} else if ("\"\"\\n\"\"".equals(value)) {
|
||||
return "\"\\\\n\"";
|
||||
}
|
||||
// ftom 20141008 - patch to fix javajet compilation errors due to hard-coded studio TableEditor mechanism
|
||||
// linked to BUILDIN properties checks, this item is a boolean set to TRUE or FALSE
|
||||
// fix is just transforming into true or false to make logging OK
|
||||
else if ("BUILDIN".equals(ep.getName())) {
|
||||
return value.toLowerCase();
|
||||
}
|
||||
|
||||
//suppose all memo fields are processed well already, no need to go though this with dangerous
|
||||
if (!isMemo && !org.talend.core.model.utils.ContextParameterUtils.isDynamic(value)) {
|
||||
if(value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) {
|
||||
if(itemFromTable && "ARGS".equals(ep.getName())) {
|
||||
value = value.substring(1, value.length());
|
||||
value = value.substring(0, value.length() - 1);
|
||||
return "\"" + checkStringQuotationMarks(value) + "\"";
|
||||
} else {
|
||||
//do nothing
|
||||
return value;
|
||||
}
|
||||
} else {
|
||||
return "\"" + checkStringQuotationMarks(value) + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
//TODO remove it
|
||||
if (value.endsWith("*")) {
|
||||
return value.substring(0, value.length() - 1) + "\"*\"";
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static String checkStringQuotationMarks(String str) {
|
||||
String result = str;
|
||||
if (result.contains("\"")) {
|
||||
result = result.replace("\"", "\\\"");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getNormalizeParameterValue(INode node, IElementParameter ep) {
|
||||
if (EParameterFieldType.TABLE.equals(ep.getFieldType())) {
|
||||
@@ -1189,7 +1357,7 @@ public class NodeUtil {
|
||||
} else if (ComponentCategory.CATEGORY_4_CAMEL.getName().equals(node.getComponent().getType())) {
|
||||
INodeConnector tmp = null;
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
|
||||
ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault()
|
||||
ICamelDesignerCoreService camelService = GlobalServiceRegister.getDefault()
|
||||
.getService(ICamelDesignerCoreService.class);
|
||||
tmp = node.getConnectorFromType(camelService.getTargetConnectionType(node));
|
||||
} else {
|
||||
@@ -1232,4 +1400,37 @@ public class NodeUtil {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isJobUsingRuntimeLineage(IProcess process) {
|
||||
// Just support DI jobs now
|
||||
boolean isSupport = isStandardJob(process) && !ProcessUtils.isTestContainer(process) && !isGuessSchemaJob(process);
|
||||
if (!isSupport) {
|
||||
return false;
|
||||
}
|
||||
RuntimeLineageManager runtimeLineageManager = new RuntimeLineageManager();
|
||||
if (runtimeLineageManager.isUseRuntimeLineageAll()) {
|
||||
return true;
|
||||
}
|
||||
if (runtimeLineageManager.getSelectedJobIds().isEmpty()) {
|
||||
runtimeLineageManager.load();
|
||||
}
|
||||
return runtimeLineageManager.isRuntimeLineageSetting(process.getId());
|
||||
}
|
||||
|
||||
public static boolean isStandardJob(IProcess process) {
|
||||
if (process != null && process instanceof IProcess2) {
|
||||
Property property = ((IProcess2) process).getProperty();
|
||||
return property != null && property.getItem() != null
|
||||
&& ComponentCategory.CATEGORY_4_DI.getName().equals(process.getComponentsType());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isGuessSchemaJob(IProcess process) {
|
||||
if (process != null && process instanceof IProcess2) {
|
||||
Property property = ((IProcess2) process).getProperty();
|
||||
return property != null && "ID".equals(property.getId()) && "Mock_job_for_Guess_schema".equals(property.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2020 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.runtime.projectsetting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.talend.commons.exception.PersistenceException;
|
||||
import org.talend.commons.ui.runtime.exception.ExceptionHandler;
|
||||
import org.talend.commons.utils.workbench.resources.ResourceUtils;
|
||||
import org.talend.repository.ProjectManager;
|
||||
import org.talend.repository.model.RepositoryConstants;
|
||||
import org.talend.repository.model.RepositoryNode;
|
||||
import org.talend.utils.json.JSONObject;
|
||||
|
||||
import us.monoid.json.JSONArray;
|
||||
|
||||
/**
|
||||
* created by hcyi on Jul 27, 2020
|
||||
* Detailled comment
|
||||
*
|
||||
*/
|
||||
public class RuntimeLineageManager {
|
||||
|
||||
public static final String RUNTIMELINEAGE_RESOURCES = "org.talend.runtimelineage"; //$NON-NLS-1$
|
||||
|
||||
public static final String RUNTIMELINEAGE_ALL = "runtimelineage.all"; //$NON-NLS-1$
|
||||
|
||||
public static final String RUNTIMELINEAGE_SELECTED = "runtimelineage.selected"; //$NON-NLS-1$
|
||||
|
||||
public static final String JOB_ID = "id"; //$NON-NLS-1$
|
||||
|
||||
public static final String RUNTIMELINEAGE_OUTPUT_PATH = "-Druntime.lineage.outputpath="; //$NON-NLS-1$
|
||||
|
||||
public static final String OUTPUT_PATH = "output.path"; //$NON-NLS-1$
|
||||
|
||||
private List<String> selectedJobIds = new ArrayList<String>();
|
||||
|
||||
private ProjectPreferenceManager prefManager = null;
|
||||
|
||||
private boolean useRuntimeLineageAll = false;
|
||||
|
||||
private String outputPath = null;
|
||||
|
||||
public RuntimeLineageManager() {
|
||||
if (prefManager == null) {
|
||||
prefManager = new ProjectPreferenceManager(RUNTIMELINEAGE_RESOURCES, true);
|
||||
}
|
||||
useRuntimeLineageAll = prefManager.getBoolean(RUNTIMELINEAGE_ALL);
|
||||
outputPath = prefManager.getValue(OUTPUT_PATH);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
String jobsJsonStr = prefManager.getValue(RUNTIMELINEAGE_SELECTED);
|
||||
if (StringUtils.isNotBlank(jobsJsonStr)) {
|
||||
JSONArray jobsJsonArray = new JSONArray(jobsJsonStr);
|
||||
for (int i = 0; i < jobsJsonArray.length(); i++) {
|
||||
Object jobJsonObj = jobsJsonArray.get(i);
|
||||
JSONObject jobJson = new JSONObject(String.valueOf(jobJsonObj));
|
||||
Iterator sortedKeys = jobJson.sortedKeys();
|
||||
String jobId = null;
|
||||
while (sortedKeys.hasNext()) {
|
||||
String key = (String) sortedKeys.next();
|
||||
if (JOB_ID.equals(key)) {
|
||||
jobId = jobJson.getString(key);
|
||||
}
|
||||
}
|
||||
if (jobId != null) {
|
||||
selectedJobIds.add(jobId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void save(List<RepositoryNode> checkedObjects, boolean all) {
|
||||
try {
|
||||
JSONArray jobsJson = new JSONArray();
|
||||
if (!all) {
|
||||
for (RepositoryNode node : checkedObjects) {
|
||||
JSONObject jobJson = new JSONObject();
|
||||
if (!jobsJson.toString().contains(node.getId())) {
|
||||
jobJson.put(JOB_ID, node.getId());
|
||||
jobsJson.put(jobJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
prefManager.setValue(RUNTIMELINEAGE_ALL, all);
|
||||
prefManager.setValue(RUNTIMELINEAGE_SELECTED, jobsJson.toString());
|
||||
prefManager.setValue(OUTPUT_PATH, outputPath);
|
||||
prefManager.save();
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRuntimeLineageSetting(String id) {
|
||||
return selectedJobIds.contains(id);
|
||||
}
|
||||
|
||||
public boolean isRuntimeLineagePrefsExist() {
|
||||
try {
|
||||
IProject project = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
|
||||
IFolder prefSettingFolder = ResourceUtils.getFolder(project, RepositoryConstants.SETTING_DIRECTORY, false);
|
||||
IFile presRuntimeLineageFile = prefSettingFolder.getFile(RUNTIMELINEAGE_RESOURCES + ".prefs"); //$NON-NLS-1$
|
||||
if (presRuntimeLineageFile.exists()) {
|
||||
return true;
|
||||
}
|
||||
} catch (PersistenceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isUseRuntimeLineageAll() {
|
||||
return this.useRuntimeLineageAll;
|
||||
}
|
||||
|
||||
public ProjectPreferenceManager getPrefManager() {
|
||||
return this.prefManager;
|
||||
}
|
||||
|
||||
public List<String> getSelectedJobIds() {
|
||||
return this.selectedJobIds;
|
||||
}
|
||||
|
||||
public void setSelectedJobIds(List<String> selectedJobIds) {
|
||||
this.selectedJobIds = selectedJobIds;
|
||||
}
|
||||
|
||||
public String getOutputPath() {
|
||||
return this.outputPath;
|
||||
}
|
||||
|
||||
public void setOutputPath(String outputPath) {
|
||||
this.outputPath = outputPath;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import java.util.Map;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.IService;
|
||||
import org.talend.core.model.components.IComponent;
|
||||
import org.talend.core.model.metadata.builder.connection.Connection;
|
||||
import org.talend.core.model.process.IElementParameter;
|
||||
import org.talend.core.model.process.INode;
|
||||
|
||||
@@ -46,6 +47,8 @@ public interface IGenericService extends IService {
|
||||
|
||||
public boolean isTcompv0(IComponent component);
|
||||
|
||||
public void validateGenericConnection(Connection conn) throws Exception;
|
||||
|
||||
public static IGenericService getService() {
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericService.class)) {
|
||||
return GlobalServiceRegister.getDefault().getService(IGenericService.class);
|
||||
|
||||
@@ -22,9 +22,11 @@ import org.talend.components.api.properties.ComponentProperties;
|
||||
import org.talend.core.IService;
|
||||
import org.talend.core.model.metadata.IMetadataTable;
|
||||
import org.talend.core.model.metadata.builder.connection.Connection;
|
||||
import org.talend.core.model.metadata.builder.connection.DatabaseConnection;
|
||||
import org.talend.core.model.metadata.builder.connection.MetadataTable;
|
||||
import org.talend.core.model.process.EComponentCategory;
|
||||
import org.talend.core.model.process.Element;
|
||||
import org.talend.core.model.process.IElement;
|
||||
import org.talend.core.model.process.INode;
|
||||
import org.talend.core.model.properties.Item;
|
||||
import org.talend.core.model.repository.ERepositoryObjectType;
|
||||
@@ -146,4 +148,14 @@ public interface IGenericWizardService extends IService {
|
||||
* @return the default action which will be invoked when double click the node.
|
||||
*/
|
||||
public ITreeContextualAction getDefaultAction(RepositoryNode node);
|
||||
|
||||
public void initAdditionalJDBCRepositoryObjType();
|
||||
|
||||
public boolean getIfAdditionalJDBCDBType(String dbType);
|
||||
|
||||
public void initAdditonalJDBCConnectionValue(DatabaseConnection connection, Composite dynamicForm, String dbType,
|
||||
String propertyId);
|
||||
|
||||
public String getDatabseNameByNode(IElement node);
|
||||
|
||||
}
|
||||
|
||||
@@ -12,13 +12,10 @@
|
||||
// ============================================================================
|
||||
package org.talend.core.service;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.talend.core.IService;
|
||||
|
||||
public interface IUpdateService extends IService {
|
||||
|
||||
boolean checkComponentNexusUpdate();
|
||||
|
||||
void syncComponentM2Jars(IProgressMonitor monitor);
|
||||
|
||||
}
|
||||
|
||||
@@ -42,4 +42,9 @@ public abstract class AbstractLoginTask implements ILoginTask {
|
||||
return gc.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRequiredAlways() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,4 +27,10 @@ public interface ILoginTask {
|
||||
public boolean isCommandlineTask();
|
||||
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Which indicates the task will be executed for each logon of a project, by default return false(execute only once
|
||||
* at the time of logon studio).
|
||||
*/
|
||||
boolean isRequiredAlways();
|
||||
}
|
||||
|
||||
@@ -268,12 +268,20 @@ public interface IProxyRepositoryFactory {
|
||||
|
||||
public abstract IRepositoryViewObject getLastVersion(Project project, String id, String relativeFolder,
|
||||
ERepositoryObjectType type) throws PersistenceException;
|
||||
|
||||
public abstract IRepositoryViewObject getLastVersion(String id, String folderPath, ERepositoryObjectType type) throws PersistenceException;
|
||||
|
||||
public abstract IRepositoryViewObject getLastVersion(String id, ERepositoryObjectType type) throws PersistenceException;
|
||||
|
||||
public abstract IRepositoryViewObject getLastVersion(String id, List<ERepositoryObjectType> types) throws PersistenceException;
|
||||
|
||||
public abstract IRepositoryViewObject getLastVersion(Project project, String id) throws PersistenceException;
|
||||
|
||||
public abstract IRepositoryViewObject getLastVersion(String id) throws PersistenceException;
|
||||
|
||||
public IRepositoryViewObject getLastRefVersion(Project project, String id) throws PersistenceException;
|
||||
|
||||
public IRepositoryViewObject getLastRefVersion(Project project, String id, String folderPath, ERepositoryObjectType type) throws PersistenceException;
|
||||
|
||||
public abstract IRepositoryViewObject getSpecificVersion(Project project, String id, String version, boolean avoidSaveProject)
|
||||
throws PersistenceException;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry exported="true" kind="lib" path="lib/jna-platform.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/jna.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/oshi-core.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
|
||||
@@ -31,7 +31,10 @@ Require-Bundle: org.apache.commons.lang,
|
||||
org.talend.themes.core,
|
||||
ca.odell.glazedlists,
|
||||
org.talend.core,
|
||||
org.apache.commons.io
|
||||
org.apache.commons.io,
|
||||
org.apache.httpcomponents.httpcore,
|
||||
org.apache.httpcomponents.httpclient,
|
||||
org.slf4j.api
|
||||
Import-Package: org.eclipse.jdt.internal.ui.workingsets
|
||||
Export-Package: org.talend.core.ui,
|
||||
org.talend.core.ui.actions,
|
||||
@@ -79,3 +82,7 @@ Bundle-Vendor: .Talend SA.
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Activator: org.talend.core.ui.CoreUIPlugin
|
||||
Bundle-Localization: plugin
|
||||
Bundle-ClassPath: lib/jna-platform.jar,
|
||||
lib/jna.jar,
|
||||
lib/oshi-core.jar,
|
||||
.
|
||||
|
||||
@@ -5,4 +5,7 @@ bin.includes = .,\
|
||||
icons/,\
|
||||
plugin.properties,\
|
||||
schema/,\
|
||||
META-INF/
|
||||
META-INF/,\
|
||||
lib/jna-platform.jar,\
|
||||
lib/jna.jar,\
|
||||
lib/oshi-core.jar
|
||||
|
||||
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.4 KiB |
@@ -24,6 +24,12 @@
|
||||
id="org.talend.core.runtime.defaultProvider"
|
||||
name="default">
|
||||
</provider>
|
||||
<provider
|
||||
collector="org.talend.core.ui.token.PerformanceTokenCollector"
|
||||
description="collect such as hardware info, I/O info, startup time"
|
||||
id="org.talend.core.ui.token.PerformanceProvider"
|
||||
name="performance">
|
||||
</provider>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
|
||||
@@ -9,4 +9,42 @@
|
||||
</parent>
|
||||
<artifactId>org.talend.core.ui</artifactId>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.oshi</groupId>
|
||||
<artifactId>oshi-core</artifactId>
|
||||
<version>5.2.5</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeScope>runtime</includeScope>
|
||||
<outputDirectory>${project.basedir}/lib</outputDirectory>
|
||||
<stripVersion>true</stripVersion>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -75,9 +75,9 @@ public class ComponentsSettingsHelper {
|
||||
hiddenComponents.put(component.getPaletteType(), new HashMap<String, Set<String>>());
|
||||
}
|
||||
if (!component.isVisibleInComponentDefinition()) {
|
||||
hiddenComponents.get(component.getPaletteType()).put(component.getName(), new HashSet<String>());
|
||||
hiddenComponents.get(component.getPaletteType()).put(component.getDisplayName(), new HashSet<String>());
|
||||
for (String family : component.getOriginalFamilyName().split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX)) {
|
||||
hiddenComponents.get(component.getPaletteType()).get(component.getName()).add(family);
|
||||
hiddenComponents.get(component.getPaletteType()).get(component.getDisplayName()).add(family);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,8 +168,8 @@ public class ComponentsSettingsHelper {
|
||||
}
|
||||
|
||||
if (hiddenComponents.containsKey(component.getPaletteType())) {
|
||||
if (hiddenComponents.get(component.getPaletteType()).containsKey(component.getName())) {
|
||||
if (hiddenComponents.get(component.getPaletteType()).get(component.getName()).contains(family)) {
|
||||
if (hiddenComponents.get(component.getPaletteType()).containsKey(component.getDisplayName())) {
|
||||
if (hiddenComponents.get(component.getPaletteType()).get(component.getDisplayName()).contains(family)) {
|
||||
// not visible if in the hidden component list;
|
||||
return false;
|
||||
}
|
||||
@@ -225,7 +225,7 @@ public class ComponentsSettingsHelper {
|
||||
EList list = emfProject.getComponentsSettings();
|
||||
if (!list.isEmpty()) {
|
||||
list.clear();
|
||||
IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(
|
||||
IRepositoryService service = GlobalServiceRegister.getDefault().getService(
|
||||
IRepositoryService.class);
|
||||
|
||||
IProxyRepositoryFactory prf = service.getProxyRepositoryFactory();
|
||||
|
||||
@@ -496,7 +496,7 @@ public class SelectRepositoryContextGroupDialog extends SelectionDialog {
|
||||
for (IContext context : manager.getListContext()) {
|
||||
String contextName = context.getName();
|
||||
if (contextName != null && repContextGrpName != null
|
||||
&& contextName.toLowerCase().equals(repContextGrpName.toLowerCase())) {
|
||||
&& contextName.equalsIgnoreCase(repContextGrpName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class AddRepositoryContextGroupCommand extends Command {
|
||||
if (name != null) {
|
||||
if (contextNames.contains(name.toLowerCase())
|
||||
|| (!isJobContextExistInRepository(nameSet, item.getDefaultContext())
|
||||
&& name.toLowerCase().equals(defaultContext.getName().toLowerCase()))) {
|
||||
&& name.equalsIgnoreCase(defaultContext.getName()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ public class AddRepositoryContextGroupCommand extends Command {
|
||||
while (it.hasNext()) {
|
||||
String selectedName = it.next();
|
||||
if (selectedName != null && defaultContextName != null) {
|
||||
if (selectedName.toLowerCase().equals(defaultContextName.toLowerCase())) {
|
||||
if (selectedName.equalsIgnoreCase(defaultContextName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ public class ContextAutoResizeTextPainter extends TextPainter {
|
||||
|
||||
private boolean changeBackgroundColor = false;
|
||||
|
||||
private boolean containsRowName = false;
|
||||
|
||||
public ContextAutoResizeTextPainter(boolean wrapText, boolean paintBg, boolean calculate) {
|
||||
super(wrapText, paintBg, calculate);
|
||||
}
|
||||
@@ -43,6 +45,8 @@ public class ContextAutoResizeTextPainter extends TextPainter {
|
||||
super.setupGCFromConfig(gc, cellStyle);
|
||||
if (cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR).equals(GUIHelper.COLOR_RED)) {
|
||||
gc.setForeground(GUIHelper.COLOR_BLACK);
|
||||
} else if (containsRowName) {
|
||||
gc.setForeground(GUIHelper.COLOR_RED);
|
||||
} else if (changeBackgroundColor) {
|
||||
gc.setForeground(GUIHelper.COLOR_WIDGET_DARK_SHADOW);
|
||||
}
|
||||
@@ -52,6 +56,9 @@ public class ContextAutoResizeTextPainter extends TextPainter {
|
||||
changeBackgroundColor = isChange;
|
||||
}
|
||||
|
||||
public void setContainsRowName(boolean containsRowName) {
|
||||
this.containsRowName = containsRowName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setNewMinLength(ILayerCell cell, int contentWidth) {
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
// ============================================================================
|
||||
package org.talend.core.ui.context.nattableTree;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
|
||||
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
||||
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsDataProvider;
|
||||
@@ -23,6 +28,7 @@ import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.talend.core.ui.context.ContextTreeTable.ContextTreeNode;
|
||||
import org.talend.core.ui.context.model.ContextTabChildModel;
|
||||
import org.talend.core.ui.context.model.ContextTabParentModel;
|
||||
import org.talend.core.ui.context.model.table.ContextTableTabParentModel;
|
||||
|
||||
/**
|
||||
@@ -33,6 +39,8 @@ public class ContextNatTableBackGroudPainter extends BackgroundPainter {
|
||||
|
||||
private IDataProvider dataProvider;
|
||||
|
||||
private Map<String, String> rowNames = new HashMap<String, String>();
|
||||
|
||||
public ContextNatTableBackGroudPainter(ICellPainter painter, IDataProvider dataProvider) {
|
||||
super(painter);
|
||||
this.dataProvider = dataProvider;
|
||||
@@ -53,9 +61,11 @@ public class ContextNatTableBackGroudPainter extends BackgroundPainter {
|
||||
ContextTabChildModel rowChildModel = (ContextTabChildModel) rowNode.getTreeData();
|
||||
if (rowChildModel != null) {
|
||||
((ContextAutoResizeTextPainter) getWrappedPainter()).setChangeBackgroundColor(true);
|
||||
checkContainsRowName(rowNode, rowChildModel);
|
||||
}
|
||||
}
|
||||
super.paintCell(cell, gc, bounds, configRegistry);
|
||||
((ContextAutoResizeTextPainter) getWrappedPainter()).setContainsRowName(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,4 +73,33 @@ public class ContextNatTableBackGroudPainter extends BackgroundPainter {
|
||||
return super.getBackgroundColour(cell, configRegistry);
|
||||
}
|
||||
|
||||
private void checkContainsRowName(ContextTreeNode rowNode, ContextTabChildModel rowChildModel) {
|
||||
// Check any duplicate / similar variable from different context to show in red .
|
||||
String rowName = rowNode.getName();
|
||||
String parentSourceName = null;
|
||||
ContextTabParentModel rowTabParentModel = rowChildModel.getParent();
|
||||
if (rowTabParentModel != null && rowTabParentModel instanceof ContextTableTabParentModel) {
|
||||
ContextTableTabParentModel rowTableTabParentModel = (ContextTableTabParentModel) rowTabParentModel;
|
||||
parentSourceName = rowTableTabParentModel.getSourceName();
|
||||
}
|
||||
if (StringUtils.isNotBlank(rowName) && StringUtils.isNotBlank(parentSourceName)) {
|
||||
rowName = rowName.toUpperCase();
|
||||
parentSourceName = parentSourceName.toUpperCase();
|
||||
if (rowNames.containsValue(rowName)) {
|
||||
Iterator<String> iterator = rowNames.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String key = iterator.next();
|
||||
String value = rowNames.get(key);
|
||||
if (rowName.equalsIgnoreCase(value)) {
|
||||
if (!parentSourceName.equalsIgnoreCase(key)) {
|
||||
((ContextAutoResizeTextPainter) getWrappedPainter()).setContainsRowName(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rowNames.put(parentSourceName, rowName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,10 +124,10 @@ public class MetadataEmfTableEditor extends ExtendedTableModel<MetadataColumn> {
|
||||
for (int i = 0; i < lstSize; i++) {
|
||||
if (columnName.equals(metadataColumns.get(i).getLabel()) && i != beanPosition) {
|
||||
return Messages.getString("MetadataEmfTableEditor.ColumnNameExists", columnName); //$NON-NLS-1$
|
||||
} else if (columnName.toLowerCase().equals(metadataColumns.get(i).getLabel().toLowerCase()) && i != beanPosition) {
|
||||
} else if (columnName.equalsIgnoreCase(metadataColumns.get(i).getLabel()) && i != beanPosition) {
|
||||
String index = columnName.substring(0, 1);
|
||||
String last = metadataColumns.get(i).getLabel().substring(0, 1);
|
||||
if (index.toLowerCase().equals(last.toLowerCase())) {
|
||||
if (index.equalsIgnoreCase(last)) {
|
||||
return Messages.getString("MetadataTableEditor.ColumnNameIsInvalid", columnName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,10 +113,10 @@ public class MetadataTableEditor extends ExtendedTableModel<IMetadataColumn> {
|
||||
for (int i = 0; i < lstSize; i++) {
|
||||
if (columnName.equals(getBeansList().get(i).getLabel()) && i != beanPosition) {
|
||||
return Messages.getString("MetadataTableEditor.ColumnNameExists", columnName); //$NON-NLS-1$
|
||||
} else if (columnName.toLowerCase().equals(getBeansList().get(i).getLabel().toLowerCase()) && i != beanPosition) {
|
||||
} else if (columnName.equalsIgnoreCase(getBeansList().get(i).getLabel()) && i != beanPosition) {
|
||||
String index = columnName.substring(0, 1);
|
||||
String last = getBeansList().get(i).getLabel().substring(0, 1);
|
||||
if (index.toLowerCase().equals(last.toLowerCase())) {
|
||||
if (index.equalsIgnoreCase(last)) {
|
||||
return Messages.getString("MetadataTableEditor.ColumnNameIsInvalid", columnName); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class DefaultTokenCollector extends AbstractTokenCollector {
|
||||
jsonObject.put("os.arch", System.getProperty("os.arch"));
|
||||
jsonObject.put("os.version", System.getProperty("os.version"));
|
||||
tokenStudioObject.put(OS.getKey(), jsonObject);
|
||||
|
||||
|
||||
final IPreferenceStore preferenceStore = CoreUIPlugin.getDefault().getPreferenceStore();
|
||||
long syncNb = preferenceStore.getLong(COLLECTOR_SYNC_NB);
|
||||
tokenStudioObject.put(SYNC_NB.getKey(), syncNb);
|
||||
@@ -91,6 +91,7 @@ public class DefaultTokenCollector extends AbstractTokenCollector {
|
||||
} else {
|
||||
tokenStudioObject.put(STOP_COLLECTOR.getKey(), "0"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return tokenStudioObject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2020 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.ui.token;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.talend.commons.exception.CommonExceptionHandler;
|
||||
import org.talend.commons.utils.time.PerformanceStatisticUtil;
|
||||
import org.talend.commons.utils.time.PerformanceStatisticUtil.StatisticKeys;
|
||||
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.Baseboard;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.CentralProcessor.ProcessorIdentifier;
|
||||
import oshi.hardware.ComputerSystem;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import us.monoid.json.JSONObject;
|
||||
|
||||
/**
|
||||
* DOC sbliu class global comment. Detailled comment
|
||||
*/
|
||||
public class PerformanceTokenCollector extends AbstractTokenCollector {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.talend.core.ui.token.AbstractTokenCollector#collect()
|
||||
*/
|
||||
@Override
|
||||
public JSONObject collect() throws Exception {
|
||||
checkAndWait();
|
||||
|
||||
JSONObject tokenStudioObject = new JSONObject();
|
||||
//
|
||||
JSONObject jsonObjectHDInfo = new JSONObject();
|
||||
|
||||
SystemInfo si = new SystemInfo();
|
||||
HardwareAbstractionLayer hal = si.getHardware();
|
||||
CentralProcessor processor = hal.getProcessor();
|
||||
ProcessorIdentifier processorIdentifier = processor.getProcessorIdentifier();
|
||||
ComputerSystem cs = hal.getComputerSystem();//computer system
|
||||
Baseboard baseboard = cs.getBaseboard();//motherboard
|
||||
GlobalMemory memory = hal.getMemory();
|
||||
|
||||
jsonObjectHDInfo.put("computer vendor", cs.getManufacturer());
|
||||
jsonObjectHDInfo.put("board vendor", baseboard.getManufacturer());
|
||||
jsonObjectHDInfo.put("board version", baseboard.getVersion());
|
||||
jsonObjectHDInfo.put("processor", processorIdentifier.getName());
|
||||
jsonObjectHDInfo.put("physical memory", Math.ceil((memory.getTotal() /(1024d*1024*1024))) + "GB");
|
||||
tokenStudioObject.put("hardware", jsonObjectHDInfo);
|
||||
|
||||
//
|
||||
JSONObject jsonObjectIOInfo = new JSONObject();
|
||||
Properties props = PerformanceStatisticUtil.read(PerformanceStatisticUtil.getRecordingFile(),false);
|
||||
jsonObjectIOInfo.put(StatisticKeys.STARTUP_AVERAGE.get(), props.getProperty(StatisticKeys.STARTUP_AVERAGE.get()));
|
||||
jsonObjectIOInfo.put(StatisticKeys.STARTUP_MAX.get(), props.getProperty(StatisticKeys.STARTUP_MAX.get()));
|
||||
jsonObjectIOInfo.put(StatisticKeys.IO_R_MB_SEC.get(), props.getProperty(StatisticKeys.IO_R_MB_SEC.get()));
|
||||
jsonObjectIOInfo.put(StatisticKeys.IO_R_AVERAGE_MB_SEC.get(), props.getProperty(StatisticKeys.IO_R_AVERAGE_MB_SEC.get()));
|
||||
jsonObjectIOInfo.put(StatisticKeys.IO_W_MB_SEC.get(), props.getProperty(StatisticKeys.IO_W_MB_SEC.get()));
|
||||
jsonObjectIOInfo.put(StatisticKeys.IO_W_AVERAGE_MB_SEC.get(), props.getProperty(StatisticKeys.IO_W_AVERAGE_MB_SEC.get()));
|
||||
tokenStudioObject.put("performance", jsonObjectIOInfo);
|
||||
|
||||
return tokenStudioObject;
|
||||
}
|
||||
|
||||
private void checkAndWait() {
|
||||
try {
|
||||
PerformanceStatisticUtil.waitUntilFinish();
|
||||
} catch (InterruptedException e) {
|
||||
CommonExceptionHandler.log(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,15 +14,39 @@ package org.talend.core.ui.token;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.Authenticator;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.Proxy;
|
||||
import java.net.Proxy.Type;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.entity.mime.content.ByteArrayBody;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Priority;
|
||||
@@ -37,17 +61,13 @@ import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.commons.utils.network.NetworkUtil;
|
||||
import org.talend.commons.utils.network.TalendProxySelector;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.prefs.ITalendCorePrefConstants;
|
||||
import org.talend.core.ui.CoreUIPlugin;
|
||||
import org.talend.core.ui.branding.IBrandingService;
|
||||
|
||||
import us.monoid.json.JSONObject;
|
||||
import us.monoid.web.AbstractContent;
|
||||
import us.monoid.web.FormData;
|
||||
import us.monoid.web.Resty;
|
||||
import us.monoid.web.TextResource;
|
||||
import us.monoid.web.mime.MultipartContent;
|
||||
|
||||
/**
|
||||
* ggu class global comment. Detailled comment
|
||||
@@ -219,7 +239,7 @@ public final class TokenCollectorFactory {
|
||||
boolean isPoweredbyTalend = false;
|
||||
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(IBrandingService.class)) {
|
||||
IBrandingService service = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
|
||||
IBrandingService service = GlobalServiceRegister.getDefault().getService(IBrandingService.class);
|
||||
isPoweredbyTalend = service.isPoweredbyTalend();
|
||||
}
|
||||
if (isPoweredbyTalend) {
|
||||
@@ -228,26 +248,18 @@ public final class TokenCollectorFactory {
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
if (NetworkUtil.isNetworkValid()) {
|
||||
Authenticator defaultAuth = NetworkUtil.getDefaultAuthenticator();
|
||||
try {
|
||||
JSONObject tokenInfors = collectTokenInfors();
|
||||
Resty r = new Resty();
|
||||
// set back the rath for Resty.
|
||||
Field rathField = Resty.class.getDeclaredField("rath"); //$NON-NLS-1$
|
||||
rathField.setAccessible(true);
|
||||
Authenticator auth = (Authenticator) rathField.get(null);
|
||||
Authenticator.setDefault(auth);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(tokenInfors.toString().getBytes());
|
||||
gzos.close();
|
||||
AbstractContent ac = Resty.content(baos.toByteArray());
|
||||
byte[] data = baos.toByteArray();
|
||||
baos.close();
|
||||
MultipartContent mpc = Resty.form(new FormData("data", ac)); //$NON-NLS-1$
|
||||
|
||||
TextResource result = r.text("https://www.talend.com/TalendRegisterWS/tokenstudio_v2.php", mpc); //$NON-NLS-1$
|
||||
String resultStr = new JSONObject(result.toString()).getString("result"); //$NON-NLS-1$
|
||||
String responseString = sendData(data);
|
||||
String resultStr = new JSONObject(responseString).getString("result"); //$NON-NLS-1$
|
||||
boolean okReturned = (resultStr != null && resultStr.endsWith("OK")); //$NON-NLS-1$
|
||||
if (okReturned) {
|
||||
// set new days
|
||||
@@ -267,7 +279,6 @@ public final class TokenCollectorFactory {
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
} finally {
|
||||
Authenticator.setDefault(defaultAuth);
|
||||
}
|
||||
}
|
||||
return org.eclipse.core.runtime.Status.OK_STATUS;
|
||||
@@ -288,4 +299,84 @@ public final class TokenCollectorFactory {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addProxy(String url, HttpClientBuilder clientBuilder) throws URISyntaxException {
|
||||
TalendProxySelector proxySelector = TalendProxySelector.getInstance();
|
||||
final List<Proxy> proxyList = proxySelector.getDefaultProxySelector().select(new URI(url));
|
||||
Proxy usedProxy = null;
|
||||
if (proxyList != null && !proxyList.isEmpty()) {
|
||||
usedProxy = proxyList.get(0);
|
||||
}
|
||||
|
||||
if (usedProxy != null) {
|
||||
if (!Type.DIRECT.equals(usedProxy.type())) {
|
||||
final Proxy finalProxy = usedProxy;
|
||||
InetSocketAddress address = (InetSocketAddress) finalProxy.address();
|
||||
String proxyServer = address.getHostString();
|
||||
int proxyPort = address.getPort();
|
||||
PasswordAuthentication proxyAuthentication = proxySelector.getHttpPasswordAuthentication();
|
||||
if (proxyAuthentication != null) {
|
||||
String proxyUser = proxyAuthentication.getUserName();
|
||||
if (StringUtils.isNotBlank(proxyUser)) {
|
||||
String proxyPassword = "";
|
||||
char[] passwordChars = proxyAuthentication.getPassword();
|
||||
if (passwordChars != null) {
|
||||
proxyPassword = new String(passwordChars);
|
||||
}
|
||||
BasicCredentialsProvider credProvider = new BasicCredentialsProvider();
|
||||
credProvider.setCredentials(new AuthScope(proxyServer, proxyPort),
|
||||
new UsernamePasswordCredentials(proxyUser, proxyPassword));
|
||||
clientBuilder.setDefaultCredentialsProvider(credProvider);
|
||||
}
|
||||
}
|
||||
HttpHost proxyHost = new HttpHost(proxyServer, proxyPort);
|
||||
clientBuilder.setProxy(proxyHost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String sendData(byte[] data) throws Exception {
|
||||
CloseableHttpClient client = null;
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
final String url = "https://www.talend.com/TalendRegisterWS/tokenstudio_v2.php";
|
||||
|
||||
HttpClientBuilder clientBuilder = HttpClients.custom();
|
||||
clientBuilder.disableCookieManagement();
|
||||
addProxy(url, clientBuilder);
|
||||
client = clientBuilder.build();
|
||||
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
httpPost.setConfig(RequestConfig.DEFAULT);
|
||||
|
||||
MultipartEntityBuilder dataBuilder = MultipartEntityBuilder.create();
|
||||
dataBuilder.addPart("data", new ByteArrayBody(data, null));
|
||||
HttpEntity reqEntity = dataBuilder.build();
|
||||
httpPost.setEntity(reqEntity);
|
||||
|
||||
response = client.execute(httpPost, HttpClientContext.create());
|
||||
StatusLine statusLine = response.getStatusLine();
|
||||
String responseStr = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
||||
if (HttpURLConnection.HTTP_OK != statusLine.getStatusCode()) {
|
||||
throw new Exception(statusLine.toString() + ", server message: [" + responseStr + "]");
|
||||
}
|
||||
return responseStr;
|
||||
} finally {
|
||||
if (response != null) {
|
||||
try {
|
||||
response.close();
|
||||
} catch (Throwable e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
if (client != null) {
|
||||
try {
|
||||
client.close();
|
||||
} catch (Throwable e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.9 KiB |
@@ -462,19 +462,25 @@ public class TalendTextUtils {
|
||||
return TalendQuoteUtils.removeQuotes(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Deprecated use org.talend.utils.string.StudioContextUtils.removeQuotesIfExist instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static String removeQuotesIfExist(String text) {
|
||||
return TalendQuoteUtils.removeQuotesIfExist(text);
|
||||
return org.talend.utils.string.StudioContextUtils.removeQuotesIfExist(text,
|
||||
org.talend.utils.string.StudioContextUtils.QUOTATION_MARK);
|
||||
}
|
||||
|
||||
/**
|
||||
* qzhang Comment method "removeQuotes".
|
||||
* @Deprecated use org.talend.utils.string.StudioContextUtils.removeQuotes
|
||||
*
|
||||
* @param text
|
||||
* @param quotation_mark2
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static String removeQuotes(String text, String quotation) {
|
||||
return TalendQuoteUtils.removeQuotes(text, quotation);
|
||||
return org.talend.utils.string.StudioContextUtils.removeQuotes(text, quotation);
|
||||
}
|
||||
|
||||
public static boolean isEnclosed(String text) {
|
||||
@@ -489,41 +495,12 @@ public class TalendTextUtils {
|
||||
return TalendQuoteUtils.getStringDeclare();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Deprecated use org.talend.utils.string.StudioContextUtils.encodeValue instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static String trimParameter(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
int length = value.length();
|
||||
String result = removeQuotes(value);
|
||||
if (length > 1
|
||||
&& (((value.startsWith("\"") && value.endsWith("\""))) || (value.startsWith("\'") && value.endsWith("\'")))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
result = value.substring(1, length - 1);
|
||||
|
||||
if (result.contains("\\")) { //$NON-NLS-1$
|
||||
result = result.replaceAll("\\\\n", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
result = result.replaceAll("\\\\b", "\b"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
result = result.replaceAll("\\\\f", "\f"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
result = result.replaceAll("\\\\r", "\r"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
result = result.replaceAll("\\\\t", "\t"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
result = result.replaceAll("\\\\\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
result = result.replaceAll("\\\\\\\\", "\\\\"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
// handle unicode
|
||||
if (result.contains("\\u")) {
|
||||
for (int indexStart = 0; result.indexOf("\\u", indexStart) >= 0; indexStart = result.indexOf("\\u", indexStart)) {
|
||||
if (result.indexOf("\\u", indexStart) + 5 <= result.length()) { //$NON-NLS-1$
|
||||
int unicodeStart = result.indexOf("\\u"); //$NON-NLS-1$
|
||||
int unicodeEnd = unicodeStart + 5;
|
||||
result = result.substring(0, Math.max(0, unicodeStart))
|
||||
+ StringEscapeUtils.unescapeJava(result.substring(unicodeStart, unicodeEnd + 1))
|
||||
+ result.substring(Math.min(unicodeEnd + 1, result.length()), result.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return org.talend.utils.string.StudioContextUtils.encodeValue(value);
|
||||
}
|
||||
|
||||
public static String getQuoteChar() {
|
||||
|
||||
@@ -23,9 +23,11 @@ import org.eclipse.emf.common.util.URI;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
import org.talend.commons.exception.PersistenceException;
|
||||
import org.talend.commons.exception.SystemException;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.IService;
|
||||
import org.talend.core.model.general.Project;
|
||||
import org.talend.core.model.process.INode;
|
||||
import org.talend.core.model.properties.Property;
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
|
||||
/**
|
||||
@@ -78,4 +80,18 @@ public interface ICoreTisService extends IService {
|
||||
|
||||
Set<String> getComponentBlackList();
|
||||
|
||||
public void afterImport (Property property) throws PersistenceException;
|
||||
|
||||
boolean hasNewPatchInPatchesFolder();
|
||||
|
||||
boolean isDefaultLicenseAndProjectType();
|
||||
|
||||
void refreshPatchesFolderCache();
|
||||
|
||||
static ICoreTisService get() {
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICoreTisService.class)) {
|
||||
return GlobalServiceRegister.getDefault().getService(ICoreTisService.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ package org.talend.datatools.xml.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* This class is a Utility class which is used to help UI to populate the list of possible XPath Expressions.
|
||||
@@ -89,7 +90,7 @@ final public class XPathPopulationUtil {
|
||||
}
|
||||
String tempRootPath = rootPath + UtilConstants.XPATH_SLASH;
|
||||
if (columnPath.startsWith(tempRootPath)) {
|
||||
return columnPath.replaceFirst("\\Q" + rootPath + "\\E", "");
|
||||
return columnPath.replaceFirst(Pattern.quote(rootPath), "");
|
||||
} else {
|
||||
return getXPathExpression(rootPath, columnPath);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.surefire</groupId>
|
||||
<artifactId>surefire-junit4</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<version>2.20</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
@@ -23,7 +23,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<version>4.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<artifactId>studio-tacokit-dependencies</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<properties>
|
||||
<tacokit.components.version>1.11.0-SNAPSHOT</tacokit.components.version>
|
||||
<tacokit.components.version>1.14.0-SNAPSHOT</tacokit.components.version>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<tcomp.version>1.1.15</tcomp.version>
|
||||
<tcomp.version>1.1.25</tcomp.version>
|
||||
<slf4j.version>1.7.25</slf4j.version>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ import static org.talend.designer.maven.model.TalendJavaProjectConstants.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -55,6 +57,7 @@ import org.talend.core.context.Context;
|
||||
import org.talend.core.context.RepositoryContext;
|
||||
import org.talend.core.model.general.ILibrariesService;
|
||||
import org.talend.core.model.general.ModuleNeeded;
|
||||
import org.talend.core.model.general.Project;
|
||||
import org.talend.core.model.process.ProcessUtils;
|
||||
import org.talend.core.model.properties.Item;
|
||||
import org.talend.core.model.properties.ProjectReference;
|
||||
@@ -169,9 +172,18 @@ public class AggregatorPomsHelper {
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
updateCodeProject(monitor, ERepositoryObjectType.ROUTINES, forceBuild);
|
||||
if (ProcessUtils.isRequiredBeans(null)) {
|
||||
updateCodeProject(monitor, ERepositoryObjectType.valueOf("BEANS"), forceBuild); //$NON-NLS-1$
|
||||
Project currentProject = ProjectManager.getInstance().getCurrentProject();
|
||||
for (ERepositoryObjectType codeType : ERepositoryObjectType.getAllTypesOfCodes()) {
|
||||
try {
|
||||
if (CodeM2CacheManager.needUpdateCodeProject(currentProject, codeType)) {
|
||||
ITalendProcessJavaProject codeProject = getCodesProject(codeType);
|
||||
updateCodeProjectPom(monitor, codeType, codeProject.getProjectPom());
|
||||
buildAndInstallCodesProject(monitor, codeType, true, forceBuild);
|
||||
CodeM2CacheManager.updateCodeProjectCache(currentProject, codeType);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -179,16 +191,6 @@ public class AggregatorPomsHelper {
|
||||
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnit);
|
||||
}
|
||||
|
||||
private void updateCodeProject(IProgressMonitor monitor, ERepositoryObjectType codeType, boolean forceBuild) {
|
||||
try {
|
||||
ITalendProcessJavaProject codeProject = getCodesProject(codeType);
|
||||
updateCodeProjectPom(monitor, codeType, codeProject.getProjectPom());
|
||||
buildAndInstallCodesProject(monitor, codeType, true, forceBuild);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCodeProjectPom(IProgressMonitor monitor, ERepositoryObjectType type, IFile pomFile)
|
||||
throws Exception {
|
||||
if (type != null) {
|
||||
@@ -209,27 +211,15 @@ public class AggregatorPomsHelper {
|
||||
}
|
||||
|
||||
public static void updateAllCodesProjectNeededModules(IProgressMonitor monitor) {
|
||||
updateCodesProjectNeededModulesByType(ERepositoryObjectType.ROUTINES, monitor);
|
||||
if (ProcessUtils.isRequiredBeans(null)) {
|
||||
updateCodesProjectNeededModulesByType(ERepositoryObjectType.valueOf("BEANS"), monitor); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateCodesProjectNeededModulesByType(ERepositoryObjectType codeType,
|
||||
IProgressMonitor monitor) {
|
||||
Set<ModuleNeeded> neededModules = null;
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
|
||||
ILibrariesService librariesService =
|
||||
(ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
|
||||
neededModules = librariesService.getCodesModuleNeededs(codeType);
|
||||
}
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
|
||||
ILibraryManagerService repositoryBundleService =
|
||||
(ILibraryManagerService) GlobalServiceRegister.getDefault().getService(
|
||||
ILibraryManagerService.class);
|
||||
if (neededModules != null && !neededModules.isEmpty()) {
|
||||
repositoryBundleService.installModules(neededModules, monitor);
|
||||
}
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)
|
||||
&& GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
|
||||
Set<ModuleNeeded> neededModules = new HashSet<>();
|
||||
ILibrariesService librariesService = GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
|
||||
ERepositoryObjectType.getAllTypesOfCodes()
|
||||
.forEach(c -> neededModules.addAll(librariesService.getCodesModuleNeededs(c)));
|
||||
ILibraryManagerService repositoryBundleService = GlobalServiceRegister.getDefault()
|
||||
.getService(ILibraryManagerService.class);
|
||||
repositoryBundleService.installModules(neededModules, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +256,7 @@ public class AggregatorPomsHelper {
|
||||
if (install) {
|
||||
Map<String, Object> argumentsMap = new HashMap<>();
|
||||
argumentsMap.put(TalendProcessArgumentConstant.ARG_GOAL, TalendMavenConstants.GOAL_INSTALL);
|
||||
argumentsMap.put(TalendProcessArgumentConstant.ARG_PROGRAM_ARGUMENTS, "-Dmaven.main.skip=true"); //$NON-NLS-1$
|
||||
argumentsMap.put(TalendProcessArgumentConstant.ARG_PROGRAM_ARGUMENTS, TalendMavenConstants.ARG_MAIN_SKIP);
|
||||
codeProject.buildModules(monitor, null, argumentsMap);
|
||||
BuildCacheManager.getInstance().updateCodeLastBuildDate(codeType);
|
||||
}
|
||||
@@ -328,26 +318,10 @@ public class AggregatorPomsHelper {
|
||||
}
|
||||
|
||||
public static void addToParentModules(IFile pomFile, Property property, boolean checkFilter) throws Exception {
|
||||
// Check relation for ESB service job, should not be added into main pom
|
||||
if (property != null) {
|
||||
List<Relation> relations = RelationshipItemBuilder.getInstance().getItemsRelatedTo(property.getId(),
|
||||
property.getVersion(), RelationshipItemBuilder.JOB_RELATION);
|
||||
for (Relation relation : relations) {
|
||||
if (RelationshipItemBuilder.SERVICES_RELATION.equals(relation.getType())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!checkIfCanAddToParentModules(property, checkFilter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkFilter) {
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(IFilterService.class)) {
|
||||
IFilterService filterService = (IFilterService) GlobalServiceRegister.getDefault()
|
||||
.getService(IFilterService.class);
|
||||
if (property != null && !filterService.isFilterAccepted(property.getItem(), PomIdsHelper.getPomFilter())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
IFile parentPom = getParentModulePomFile(pomFile);
|
||||
if (parentPom != null) {
|
||||
if (!parentPom.isSynchronized(IResource.DEPTH_ZERO)) {
|
||||
@@ -367,6 +341,36 @@ public class AggregatorPomsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkIfCanAddToParentModules(Property property, boolean checkFilter) {
|
||||
// Check relation for ESB service job, should not be added into main pom
|
||||
if (property != null) {
|
||||
List<Relation> relations = RelationshipItemBuilder.getInstance().getItemsRelatedTo(property.getId(),
|
||||
property.getVersion(), RelationshipItemBuilder.JOB_RELATION);
|
||||
for (Relation relation : relations) {
|
||||
if (RelationshipItemBuilder.SERVICES_RELATION.equals(relation.getType())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// for import won't add for exclude option
|
||||
if (property.getItem() != null && property.getItem().getState() != null && property.getItem().getState().isDeleted()
|
||||
&& PomIdsHelper.getIfExcludeDeletedItems(property)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkFilter) {
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(IFilterService.class)) {
|
||||
IFilterService filterService = (IFilterService) GlobalServiceRegister.getDefault()
|
||||
.getService(IFilterService.class);
|
||||
if (property != null && !filterService.isFilterAccepted(property.getItem(), PomIdsHelper.getPomFilter())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void removeFromParentModules(IFile pomFile) throws Exception {
|
||||
IFile parentPom = getParentModulePomFile(pomFile);
|
||||
if (parentPom != null) {
|
||||
@@ -384,6 +388,69 @@ public class AggregatorPomsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeAllVersionsFromParentModules(Property property) throws Exception {
|
||||
IFile parentPom = getParentModulePomFile(
|
||||
AggregatorPomsHelper.getItemPomFolder(property).getFile(TalendMavenConstants.POM_FILE_NAME));
|
||||
if (parentPom == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> relativePathList = new ArrayList<String>();
|
||||
List<IRepositoryViewObject> allVersion = ProxyRepositoryFactory.getInstance().getAllVersion(property.getId());
|
||||
for (IRepositoryViewObject object : allVersion) {
|
||||
IFile pomFile = AggregatorPomsHelper.getItemPomFolder(object.getProperty())
|
||||
.getFile(TalendMavenConstants.POM_FILE_NAME);
|
||||
String relativePath = pomFile.getParent().getLocation().makeRelativeTo(parentPom.getParent().getLocation())
|
||||
.toPortableString();
|
||||
if (StringUtils.isNotBlank(relativePath)) {
|
||||
relativePathList.add(relativePath);
|
||||
}
|
||||
}
|
||||
|
||||
Model model = MavenPlugin.getMaven().readModel(parentPom.getContents());
|
||||
List<String> modules = model.getModules();
|
||||
if (modules != null && modules.size() > 0) {
|
||||
modules.removeAll(relativePathList);
|
||||
PomUtil.savePom(null, model, parentPom);
|
||||
}
|
||||
}
|
||||
|
||||
public static void restoreAllVersionsFromParentModules(Property property) throws Exception {
|
||||
IFile parentPom = getParentModulePomFile(
|
||||
AggregatorPomsHelper.getItemPomFolder(property).getFile(TalendMavenConstants.POM_FILE_NAME));
|
||||
if (parentPom == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> relativePathList = new ArrayList<String>();
|
||||
Model model = MavenPlugin.getMaven().readModel(parentPom.getContents());
|
||||
List<String> modules = model.getModules();
|
||||
if (modules == null) {
|
||||
modules = new ArrayList<>();
|
||||
model.setModules(modules);
|
||||
}
|
||||
|
||||
List<IRepositoryViewObject> allVersion = ProxyRepositoryFactory.getInstance().getAllVersion(property.getId());
|
||||
for (IRepositoryViewObject object : allVersion) {
|
||||
Property itemProperty = object.getProperty();
|
||||
if (!checkIfCanAddToParentModules(itemProperty, true)) {
|
||||
continue;
|
||||
}
|
||||
IFile pomFile = AggregatorPomsHelper.getItemPomFolder(object.getProperty(), object.getVersion())
|
||||
.getFile(TalendMavenConstants.POM_FILE_NAME);
|
||||
|
||||
String relativePath = pomFile.getParent().getLocation().makeRelativeTo(parentPom.getParent().getLocation())
|
||||
.toPortableString();
|
||||
if (StringUtils.isNoneBlank(relativePath) && !modules.contains(relativePath)) {
|
||||
relativePathList.add(relativePath);
|
||||
}
|
||||
}
|
||||
Collections.sort(relativePathList);
|
||||
modules.addAll(relativePathList);
|
||||
PomUtil.savePom(null, model, parentPom);
|
||||
|
||||
}
|
||||
|
||||
private static IFile getParentModulePomFile(IFile pomFile) {
|
||||
IFile parentPom = null;
|
||||
if (pomFile == null || pomFile.getParent() == null || pomFile.getParent().getParent() == null) {
|
||||
@@ -538,7 +605,10 @@ public class AggregatorPomsHelper {
|
||||
String jobFolderName = getJobProjectFolderName(property.getLabel(), version);
|
||||
ERepositoryObjectType type = ERepositoryObjectType.getItemType(property.getItem());
|
||||
IFolder jobFolder = helper.getProcessFolder(type).getFolder(itemRelativePath).getFolder(jobFolderName);
|
||||
createFoldersIfNeeded(jobFolder);
|
||||
List<ERepositoryObjectType> allTypesOfProcess2 = ERepositoryObjectType.getAllTypesOfProcess2();
|
||||
if (allTypesOfProcess2.contains(type)) {
|
||||
createFoldersIfNeeded(jobFolder);
|
||||
}
|
||||
return jobFolder;
|
||||
}
|
||||
|
||||
|
||||
@@ -395,4 +395,25 @@ public class BuildCacheManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsMultipleVersionModules() {
|
||||
return containsMultipleVersionModules(currentJobletmodules) || containsMultipleVersionModules(currentJobmodules);
|
||||
}
|
||||
|
||||
private static boolean containsMultipleVersionModules(Set<String> mods) {
|
||||
Set<String> joblets = new HashSet<String>();
|
||||
for (String mod : mods) {
|
||||
int idx = mod.lastIndexOf('_');
|
||||
if (idx == -1) {
|
||||
continue;
|
||||
}
|
||||
String jobletWithoutVersion = mod.substring(0, idx);
|
||||
if (joblets.contains(jobletWithoutVersion)) {
|
||||
return true;
|
||||
} else {
|
||||
joblets.add(jobletWithoutVersion);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2020 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.designer.maven.tools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.m2e.core.MavenPlugin;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.commons.exception.PersistenceException;
|
||||
import org.talend.core.model.general.Project;
|
||||
import org.talend.core.model.properties.Property;
|
||||
import org.talend.core.model.repository.ERepositoryObjectType;
|
||||
import org.talend.core.model.repository.IRepositoryViewObject;
|
||||
import org.talend.core.repository.model.ProxyRepositoryFactory;
|
||||
import org.talend.core.runtime.repository.item.ItemProductKeys;
|
||||
import org.talend.cwm.helper.ResourceHelper;
|
||||
import org.talend.designer.maven.utils.PomIdsHelper;
|
||||
|
||||
public class CodeM2CacheManager {
|
||||
|
||||
private static final String KEY_SEPERATOR = "|"; //$NON-NLS-1$
|
||||
|
||||
public static boolean needUpdateCodeProject(Project project, ERepositoryObjectType codeType) {
|
||||
try {
|
||||
String projectTechName = project.getTechnicalLabel();
|
||||
File cacheFile = getCacheFile(projectTechName, codeType);
|
||||
if (!cacheFile.exists()) {
|
||||
return true;
|
||||
}
|
||||
Properties cache = new Properties();
|
||||
cache.load(new FileInputStream(cacheFile));
|
||||
List<IRepositoryViewObject> allCodes = ProxyRepositoryFactory.getInstance().getAll(project, codeType, false);
|
||||
// check A/D
|
||||
if (allCodes.size() != cache.size()) {
|
||||
return true;
|
||||
}
|
||||
// check M
|
||||
for (IRepositoryViewObject codeItem : allCodes) {
|
||||
Property property = codeItem.getProperty();
|
||||
String key = getCacheKey(projectTechName, property);
|
||||
String cachedTimestamp = cache.getProperty(key);
|
||||
if (cachedTimestamp != null) {
|
||||
Date currentDate = ResourceHelper.dateFormat().parse(getCacheDate(projectTechName, property));
|
||||
Date cachedDate = ResourceHelper.dateFormat().parse(cachedTimestamp);
|
||||
if (currentDate.compareTo(cachedDate) != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (PersistenceException | IOException | ParseException e) {
|
||||
ExceptionHandler.process(e);
|
||||
// if any exception, still update in case breaking build job
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void updateCodeProjectCache(Project project, ERepositoryObjectType codeType) {
|
||||
String projectTechName = project.getTechnicalLabel();
|
||||
File cacheFile = getCacheFile(projectTechName, codeType);
|
||||
try (OutputStream out = new FileOutputStream(cacheFile)) {
|
||||
List<IRepositoryViewObject> allCodes = ProxyRepositoryFactory.getInstance().getAll(project, codeType, false);
|
||||
Properties cache = new Properties();
|
||||
for (IRepositoryViewObject codeItem : allCodes) {
|
||||
Property property = codeItem.getProperty();
|
||||
String key = getCacheKey(projectTechName, property);
|
||||
String value = getCacheDate(projectTechName, property);
|
||||
cache.put(key, value);
|
||||
}
|
||||
cache.store(out, StringUtils.EMPTY);
|
||||
} catch (PersistenceException | IOException e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static File getCacheFile(String projectTechName, ERepositoryObjectType codeType) {
|
||||
String cacheFileName = PomIdsHelper.getProjectGroupId(projectTechName) + "." + codeType.name().toLowerCase() + "-" //$NON-NLS-1$ //$NON-NLS-2$
|
||||
+ PomIdsHelper.getCodesVersion(projectTechName) + ".cache"; // $NON-NLS-1$
|
||||
return new File(MavenPlugin.getMaven().getLocalRepositoryPath(), cacheFileName);
|
||||
}
|
||||
|
||||
private static String getCacheKey(String projectTechName, Property property) {
|
||||
return projectTechName + KEY_SEPERATOR + property.getId() + KEY_SEPERATOR + property.getVersion(); // $NON-NLS-1$
|
||||
}
|
||||
|
||||
private static String getCacheDate(String projectTechName, Property property) {
|
||||
return (String) property.getAdditionalProperties().get(ItemProductKeys.DATE.getModifiedKey());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,6 +45,7 @@ import org.talend.core.model.utils.JavaResourcesHelper;
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
import org.talend.core.runtime.maven.MavenConstants;
|
||||
import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
import org.talend.core.runtime.process.LastGenerationInfo;
|
||||
import org.talend.core.runtime.process.TalendProcessArgumentConstant;
|
||||
import org.talend.core.runtime.projectsetting.IProjectSettingTemplateConstants;
|
||||
import org.talend.core.runtime.repository.build.IMavenPomCreator;
|
||||
@@ -52,6 +53,7 @@ import org.talend.core.ui.ITestContainerProviderService;
|
||||
import org.talend.designer.maven.model.TalendMavenConstants;
|
||||
import org.talend.designer.maven.template.ETalendMavenVariables;
|
||||
import org.talend.designer.maven.tools.ProcessorDependenciesManager;
|
||||
import org.talend.designer.maven.utils.JobUtils;
|
||||
import org.talend.designer.maven.utils.PomIdsHelper;
|
||||
import org.talend.designer.maven.utils.PomUtil;
|
||||
import org.talend.designer.runprocess.IBigDataProcessor;
|
||||
@@ -134,9 +136,16 @@ 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.
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobGroupId, PomIdsHelper.getJobGroupId(property));
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobArtifactId, PomIdsHelper.getJobArtifactId(property));
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobVersion, PomIdsHelper.getJobVersion(property));
|
||||
|
||||
if (JobUtils.isJob(property) && ProcessUtils.isChildRouteProcess(process)) {
|
||||
JobInfo lastMainJob = LastGenerationInfo.getInstance().getLastMainJob();
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobGroupId, PomIdsHelper.getJobGroupId(lastMainJob.getProcessor().getProperty()));
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobVersion, PomIdsHelper.getJobVersion(lastMainJob.getProcessor().getProperty()));
|
||||
}else {
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobGroupId, PomIdsHelper.getJobGroupId(property));
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobVersion, PomIdsHelper.getJobVersion(property));
|
||||
}
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobArtifactId, PomIdsHelper.getJobArtifactId(property));
|
||||
variablesValuesMap.put(ETalendMavenVariables.TalendJobVersion, property.getVersion());
|
||||
final String jobName = JavaResourcesHelper.escapeFileName(process.getName());
|
||||
variablesValuesMap.put(ETalendMavenVariables.JobName, jobName);
|
||||
|
||||
@@ -19,11 +19,14 @@ import java.util.Set;
|
||||
|
||||
import org.talend.commons.exception.PersistenceException;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.model.process.INode;
|
||||
import org.talend.core.model.process.IProcess;
|
||||
import org.talend.core.model.process.JobInfo;
|
||||
import org.talend.core.model.process.ProcessUtils;
|
||||
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.ERepositoryObjectType;
|
||||
import org.talend.core.model.repository.IRepositoryViewObject;
|
||||
import org.talend.core.model.utils.JavaResourcesHelper;
|
||||
import org.talend.core.runtime.CoreRuntimePlugin;
|
||||
@@ -97,5 +100,22 @@ public class JobUtils {
|
||||
}
|
||||
return clonedJobInfos;
|
||||
}
|
||||
|
||||
public static boolean isJob(JobInfo job) {
|
||||
if (job != null && job.getProcessItem() != null) {
|
||||
Property p = job.getProcessItem().getProperty();
|
||||
if (p != null) {
|
||||
return isJob(p);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isJob(Property p) {
|
||||
if (p != null) {
|
||||
return ERepositoryObjectType.getType(p).equals(ERepositoryObjectType.PROCESS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -247,6 +247,17 @@ public class PomIdsHelper {
|
||||
return version;
|
||||
}
|
||||
|
||||
public static String getCustomJobVersion(Property property) {
|
||||
String version = null;
|
||||
if (property != null) {
|
||||
if (property.getAdditionalProperties() != null) {
|
||||
version = (String) property.getAdditionalProperties().get(MavenConstants.NAME_USER_VERSION);
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
public static String getJobVersion(JobInfo jobInfo) {
|
||||
if (jobInfo != null) {
|
||||
return jobInfo.getJobVersion();
|
||||
|
||||
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 609 B |
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.talend.libraries.apache.google</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>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,6 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Google
|
||||
Bundle-SymbolicName: org.talend.libraries.apache.google
|
||||
Bundle-Version: 7.4.1.qualifier
|
||||
Eclipse-BundleShape: dir
|
||||