blob: e6e6192cd841890726e0435f1f2989dff3e6ad67 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/*******************************************************************************
* Copyright (c) 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.core.internal.weave;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jpt.common.core.gen.JptGenerator;
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
import org.eclipse.jpt.common.utility.internal.StringTools;
/**
* StaticWeave
* Running Static Weaving from Project's classpath
*/
public class StaticWeave extends AbstractJptGenerator
{
static public String LAUNCH_CONFIG_NAME = "Static Weaving Run Config"; //$NON-NLS-1$
static public String WEAVING_PACKAGE_NAME = "org.eclipse.persistence.tools.weaving.jpa"; //$NON-NLS-1$
static public String WEAVING_CLASS = WEAVING_PACKAGE_NAME + ".StaticWeave"; //$NON-NLS-1$
private String source;
private String target;
private String loglevel;
private String persistenceinfo;
private final String mainType;
// ********** constructors **********
public StaticWeave(
IJavaProject javaProject,
String source,
String target,
String loglevel,
String persistenceinfo) {
super(javaProject);
this.source = source;
this.target = target;
this.loglevel = loglevel;
this.persistenceinfo = persistenceinfo;
this.mainType = WEAVING_CLASS;
}
// ********** overrides **********
@Override
protected String getMainType() {
return this.mainType;
}
@Override
protected String getLaunchConfigName() {
return LAUNCH_CONFIG_NAME;
}
@Override
protected void specifyJRE() {
// do nothing
}
// ********** behavior **********
@Override
protected void preGenerate(IProgressMonitor monitor) {
// nothing to do yet...
}
// ********** Launch Configuration Setup **********
@Override
protected List<String> buildClasspath() throws CoreException {
List<String> classpath = new ArrayList<String>();
// Default Project classpath
classpath.add(this.getDefaultProjectClasspathEntry().getMemento());
// System Library
classpath.add(this.getSystemLibraryClasspathEntry().getMemento());
// Containers classpath
for(IRuntimeClasspathEntry containerClasspathEntry: this.getContainersClasspathEntries()) {
classpath.add(containerClasspathEntry.getMemento());
}
return classpath;
}
@Override
protected void specifyProgramArguments() {
StringBuffer programArguments = new StringBuffer();
if(StringTools.isBlank(this.source)) {
throw new RuntimeException("Source directory cannot be empty"); //$NON-NLS-1$
}
if(StringTools.isBlank(this.target)) {
throw new RuntimeException("Target directory cannot be empty"); //$NON-NLS-1$
}
if( ! StringTools.isBlank(this.loglevel)) {
programArguments.append("-loglevel "); //$NON-NLS-1$
programArguments.append(this.loglevel);
}
if( ! StringTools.isBlank(this.persistenceinfo)) {
programArguments.append(" -persistenceinfo "); //$NON-NLS-1$
programArguments.append(StringTools.quote(this.persistenceinfo));
}
programArguments.append(' ');
programArguments.append(StringTools.quote(this.source));
programArguments.append(' ');
programArguments.append(StringTools.quote(this.target));
this.getLaunchConfig().setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArguments.toString());
}
// ********** queries **********
private List<IRuntimeClasspathEntry> getContainersClasspathEntries() throws CoreException {
ArrayList<IRuntimeClasspathEntry> classpathEntries = new ArrayList<IRuntimeClasspathEntry>();
for(IClasspathEntry classpathEntry: this.getJavaProject().getRawClasspath()) {
if(classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
IClasspathContainer container = JavaCore.getClasspathContainer(classpathEntry.getPath(), this.getJavaProject());
if(container != null && container.getKind() == IClasspathContainer.K_SYSTEM) {
classpathEntries.add(
JavaRuntime.newRuntimeContainerClasspathEntry(
container.getPath(),
IRuntimeClasspathEntry.BOOTSTRAP_CLASSES,
this.getJavaProject()));
}
}
}
return classpathEntries;
}
}
|