Revision 988

tmp/org.eclipse.pde.hack/.project (revision 988)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.eclipse.pde.hack</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.eclipse.pde.hack/src/org/eclipse/pde/internal/build/site/QualifierReplacer.java (revision 988)
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.build.site;
12

  
13
import com.ibm.icu.util.Calendar;
14

  
15
import java.io.BufferedReader;
16
import java.io.File;
17
import java.io.FileOutputStream;
18
import java.io.FileWriter;
19
import java.io.IOException;
20
import java.io.InputStreamReader;
21
import java.nio.charset.StandardCharsets;
22
import java.text.SimpleDateFormat;
23
import java.util.Properties;
24
import java.util.regex.Matcher;
25
import java.util.regex.Pattern;
26

  
27
import org.eclipse.pde.internal.build.AbstractScriptGenerator;
28
import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
29
import org.osgi.framework.Version;
30
//import org.tmatesoft.svn.core.SVNDirEntry;
31
//import org.tmatesoft.svn.core.SVNURL;
32
//import org.tmatesoft.svn.core.io.SVNRepository;
33
//import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
34
//import org.tmatesoft.svn.core.wc.SVNClientManager;
35
//import org.tmatesoft.svn.core.wc.SVNInfo;
36
//import org.tmatesoft.svn.core.wc.SVNRevision;
37
//import org.tmatesoft.svn.core.wc.SVNWCClient;
38

  
39
public class QualifierReplacer implements IBuildPropertiesConstants {
40
	private static final String PROPERTY_SVN = "svn";
41
	//	private static final String DOT_QUALIFIER = '.' + PROPERTY_QUALIFIER;
42
	private static String globalQualifier = null;
43

  
44

  
45
	private static void printDebug(String mess) {
46
		FileWriter writer = null;
47
		try {
48
			writer = new FileWriter(new File(System.getProperty("java.io.tmpdir"), "pde_build.txt"), true);
49
			writer.write(mess+"\n");
50
			writer.close();
51
		} catch(Exception e) {}
52
		finally {
53
			if (writer != null)
54
				try {
55
					writer.close();
56
				} catch (IOException e) {
57
					// TODO Auto-generated catch block
58
					e.printStackTrace();
59
				}
60
		}
61
	}
62
	/**
63
	 * Replaces the 'qualifier' in the given version with the qualifier replacement.
64
	 * 
65
	 * @param version version to replace qualifier in
66
	 * @param id id used when building a replacement using newVersions properties
67
	 * @param replaceTag replace qualifier with this tag instead of global qualifier, may be <code>null</code>
68
	 * @param newVersions properties that can be used to generate an alternative qualifier
69
	 * @return string version with qualifier replaced
70
	 */
71
	public static String replaceQualifierInVersion(String version, String id, String replaceTag, Properties newVersions) {
72

  
73
		//printDebug("REPLACE version="+version+" id="+id+" replaceTag="+replaceTag+" newVersions="+newVersions);
74
		//newVersions.put(PROPERTY_QUALIFIER, "fdp");
75

  
76
		if (!AbstractScriptGenerator.getPropertyAsBoolean(IBuildPropertiesConstants.PROPERTY_PACKAGER_AS_NORMALIZER))
77
			return version;
78
		if (!version.endsWith(PROPERTY_QUALIFIER))
79
			return version;
80

  
81
		String newQualifier = null;
82
		if (replaceTag == null || replaceTag.equalsIgnoreCase(PROPERTY_CONTEXT)) {
83
			if (globalQualifier != null)
84
				newQualifier = globalQualifier;
85

  
86
			if (newQualifier == null && newVersions != null && newVersions.size() != 0) { //Skip the lookup in the file if there is no entries
87
				newQualifier = (String) newVersions.get(getQualifierKey(id, version)); //First we check to see if there is a precise version
88
				if (newQualifier == null) //If not found, then lookup for the id,0.0.0
89
					newQualifier = (String) newVersions.get(id + ',' + Version.emptyVersion.toString());
90
				if (newQualifier == null)
91
					newQualifier = newVersions.getProperty(DEFAULT_MATCH_ALL);
92
			}
93

  
94

  
95
			if (newQualifier == null)
96
				newQualifier = getDateQualifier();
97
		} else if (replaceTag.equalsIgnoreCase(PROPERTY_NONE)) {
98
			newQualifier = ""; //$NON-NLS-1$
99
		} else if (replaceTag.equalsIgnoreCase(PROPERTY_SVN)) {
100
			newQualifier = getSVNQualifier(id); //$NON-NLS-1$
101
		} else {
102
			newQualifier = replaceTag;
103
		}
104

  
105
		version = version.replaceFirst(PROPERTY_QUALIFIER, newQualifier);
106
		if (version.endsWith(".")) //$NON-NLS-1$
107
			version = version.substring(0, version.length() - 1);
108
		return version;
109
	}
110

  
111
	/**
112
	 * find out SVN revision number of a project
113
	 * @param id
114
	 * @return
115
	 */
116
	public static String getSVNQualifier(String id) {
117
		String projectDirectory = new File(System.getProperty("user.home"), "workspace047/"+id+"/").getAbsolutePath();
118
		if (!projectDirectory.endsWith("/")) projectDirectory += "/";
119
		
120
		try {
121
			//		SVNWCClient client = SVNClientManager.newInstance().getWCClient();
122
			//		SVNInfo info = client.doInfo(projectDirectory, SVNRevision.WORKING);
123
			//		SVNURL location = info.getURL();
124
			//		SVNRepository repository = SVNRepositoryFactory.create(location);
125
			//		
126
			////		long latestRevision = repository.getLatestRevision();
127
			////		System.out.println("[" + location.toString() + "] latest revision: " + latestRevision); 
128
			//
129
			//
130
			//		SVNDirEntry entry = repository.info(".", -1);
131
			////		System.out.println("[" + location.toString() + "] latest revision: " + entry.getRevision());
132
			////		System.out.println("[" + location.toString() + "] latest date: " + entry.getDate());
133
			//		String svndate = entry.getDate()
134
			//printDebug("svn info in "+projectDirectory);
135
			String xml = getXML("svn","info","--xml", projectDirectory);
136
			//printDebug("xml "+xml);
137
			String rev = getRev(xml);
138
			printDebug(id+"="+rev);
139
			return rev;
140
			/*
141
		String svndate = null;
142
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd-HHmm");
143
		//SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmm");
144
		return formatter.format(svndate);
145
			 */
146
		} catch (Exception e) {
147
			e.printStackTrace();
148
			return "svn_error_"+id+"_"+projectDirectory;
149
		}
150
	}
151

  
152
	private static String getRev(String xml) {
153
		Pattern p = Pattern.compile("<commit\n" + 
154
				"   revision=\"([^\\\"]+)\"");
155
		Matcher m = p.matcher(xml);
156
		if (m.find()) {
157
			return m.group(1).trim();
158
		}
159
		printDebug("Wrong XML ? "+xml);
160
		return "error";
161
	}
162

  
163
	private static String getXML(String... args) throws IOException {
164
		ProcessBuilder builder = new ProcessBuilder(args);
165
		builder.redirectErrorStream(true);
166
		Process process = builder.start();
167
		BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));
168
		StringBuilder sb = new StringBuilder();
169
		String line = null;
170
		while ((line = reader.readLine ()) != null) {
171
			sb.append(line+"\n");
172
		}
173
		reader.close();
174
		return sb.toString();
175
	}
176

  
177
	//given a version ending in "qualifier" return the key to look up the replacement
178
	public static String getQualifierKey(String id, String version) {
179
		if (version == null || !version.endsWith(PROPERTY_QUALIFIER))
180
			return null;
181

  
182
		Version osgiVersion = new Version(version);
183
		String qualifier = osgiVersion.getQualifier();
184
		qualifier = qualifier.substring(0, qualifier.length() - PROPERTY_QUALIFIER.length());
185

  
186
		StringBuffer keyBuffer = new StringBuffer(id);
187
		keyBuffer.append(',');
188
		keyBuffer.append(osgiVersion.getMajor());
189
		keyBuffer.append('.');
190
		keyBuffer.append(osgiVersion.getMinor());
191
		keyBuffer.append('.');
192
		keyBuffer.append(osgiVersion.getMicro());
193

  
194
		if (qualifier.length() > 0) {
195
			keyBuffer.append('.');
196
			keyBuffer.append(qualifier);
197
		}
198
		return keyBuffer.toString();
199
	}
200

  
201
	/**
202
	 * Returns the current date/time as a string to be used as a qualifier
203
	 * replacement.  This is the default qualifier replacement.  Will
204
	 * be of the form YYYYMMDDHHMM.
205
	 * @return current date/time as a qualifier replacement 
206
	 */
207
	public static String getDateQualifier() {
208
		final String empty = ""; //$NON-NLS-1$
209
		int monthNbr = Calendar.getInstance().get(Calendar.MONTH) + 1;
210
		String month = (monthNbr < 10 ? "0" : empty) + monthNbr; //$NON-NLS-1$
211

  
212
		int dayNbr = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
213
		String day = (dayNbr < 10 ? "0" : empty) + dayNbr; //$NON-NLS-1$
214

  
215
		int hourNbr = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
216
		String hour = (hourNbr < 10 ? "0" : empty) + hourNbr; //$NON-NLS-1$
217

  
218
		int minuteNbr = Calendar.getInstance().get(Calendar.MINUTE);
219
		String minute = (minuteNbr < 10 ? "0" : empty) + minuteNbr; //$NON-NLS-1$
220

  
221
		return empty + Calendar.getInstance().get(Calendar.YEAR) + month + day + hour + minute;
222
	}
223

  
224
	/**
225
	 * Sets the global variable used as the qualifier replacement during calls to
226
	 * {@link #replaceQualifierInVersion(String, String, String, Properties)}
227
	 * Setting the qualifier to <code>null</code> will result in the default
228
	 * date qualifier being used.
229
	 * @param globalQualifier string replacement or <code>null</code>
230
	 */
231
	public static void setGlobalQualifier(String globalQualifier) {
232
		if (globalQualifier == null || globalQualifier.length() == 0)
233
			QualifierReplacer.globalQualifier = null;
234
		else if (globalQualifier.length() > 0 && globalQualifier.charAt(0) != '$')
235
			QualifierReplacer.globalQualifier = globalQualifier;
236
	}
237
}
0 238

  
tmp/org.eclipse.pde.hack/src/org/eclipse/pde/internal/build/site/Test.java (revision 988)
1
package org.eclipse.pde.internal.build.site;
2

  
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.IOException;
6
import java.io.InputStreamReader;
7
import java.nio.charset.StandardCharsets;
8
import java.text.SimpleDateFormat;
9
import java.util.regex.Matcher;
10
import java.util.regex.Pattern;
11

  
12
public class Test {
13

  
14
	public static String getSVNQualifier(String id) {
15
		try {
16
			File projectDirectory = new File("/home/mdecorde/workspace047/"+id);
17

  
18
			//		SVNWCClient client = SVNClientManager.newInstance().getWCClient();
19
			//		SVNInfo info = client.doInfo(projectDirectory, SVNRevision.WORKING);
20
			//		SVNURL location = info.getURL();
21
			//		SVNRepository repository = SVNRepositoryFactory.create(location);
22
			//		
23
			////		long latestRevision = repository.getLatestRevision();
24
			////		System.out.println("[" + location.toString() + "] latest revision: " + latestRevision); 
25
			//
26
			//
27
			//		SVNDirEntry entry = repository.info(".", -1);
28
			////		System.out.println("[" + location.toString() + "] latest revision: " + entry.getRevision());
29
			////		System.out.println("[" + location.toString() + "] latest date: " + entry.getDate());
30
			//		String svndate = entry.getDate()
31

  
32
			String xml = getXML("svn","info","--xml", projectDirectory.getAbsolutePath());
33
			String rev = getRev(xml);
34
			return rev;
35
			/*
36
		String svndate = null;
37
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd-HHmm");
38
		//SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmm");
39
		return formatter.format(svndate);
40
			 */
41
		} catch (Exception e) {
42
			e.printStackTrace();
43
			return "svn_error_"+id;
44
		}
45

  
46
	}
47

  
48
	private static String getRev(String xml) {
49
		Pattern p = Pattern.compile("<commit\n" + 
50
				"   revision=\"([^\\\"]+)\"");
51
		Matcher m = p.matcher(xml);
52
		if (m.find()) {
53
			return m.group(1).trim();
54
		}
55
		return "error";
56
	}
57

  
58
	private static String getXML(String... args) throws IOException {
59
		ProcessBuilder builder = new ProcessBuilder(args);
60
		builder.redirectErrorStream(true);
61
		Process process = builder.start();
62
		BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));
63
		StringBuilder sb = new StringBuilder();
64
		String line = null;
65
		while ((line = reader.readLine ()) != null) {
66
			sb.append(line+"\n");
67
		}
68
		reader.close();
69
		return sb.toString();
70
	}
71

  
72
	public static void main(String[] args) {
73
		String q = getSVNQualifier("org.txm.core");
74
		System.out.println(q);
75
	}
76
}
0 77

  
tmp/org.eclipse.pde.hack/build.properties (revision 988)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .
0 5

  
tmp/org.eclipse.pde.hack/.settings/org.eclipse.jdt.core.prefs (revision 988)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4
org.eclipse.jdt.core.compiler.compliance=1.8
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.8
0 8

  
tmp/org.eclipse.pde.hack/.classpath (revision 988)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
5
		<accessrules>
6
			<accessrule kind="accessible" pattern="**"/>
7
		</accessrules>
8
	</classpathentry>
9
	<classpathentry kind="src" path="src"/>
10
	<classpathentry kind="output" path="bin"/>
11
</classpath>
0 12

  
tmp/org.eclipse.pde.hack/META-INF/MANIFEST.MF (revision 988)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: PDE Hack
4
Bundle-SymbolicName: org.eclipse.pde.hack
5
Bundle-Version: 1.0.0.qualifier
6
Fragment-Host: org.eclipse.pde.build;bundle-version="3.9.300"
7
Automatic-Module-Name: org.eclipse.pde.hack
8
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
9
Bundle-Vendor: Textometrie.org
0 10

  

Also available in: Unified diff