Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uaaltools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
universAAL
uaaltools
Commits
ca5b30d3
Commit
ca5b30d3
authored
11 years ago
by
Manlio Bacco
Browse files
Options
Downloads
Patches
Plain Diff
fixed jar generation; now mvn:package is used
parent
57c4cf3b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/zip/CreateJar.java
+104
-66
104 additions, 66 deletions
...rc/org/universaal/tools/packaging/tool/zip/CreateJar.java
with
104 additions
and
66 deletions
mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/zip/CreateJar.java
+
104
−
66
View file @
ca5b30d3
package
org.universaal.tools.packaging.tool.zip
;
import
java.io.BufferedInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.jar.Attributes
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarOutputStream
;
import
java.util.jar.Manifest
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Properties
;
import
org.apache.maven.execution.MavenExecutionRequest
;
import
org.apache.maven.execution.MavenExecutionResult
;
import
org.eclipse.core.resources.IFile
;
import
org.eclipse.core.resources.IProject
;
import
org.eclipse.core.resources.IWorkspace
;
import
org.eclipse.core.resources.IWorkspaceDescription
;
import
org.eclipse.core.resources.ResourcesPlugin
;
import
org.eclipse.m2e.core.MavenPlugin
;
import
org.eclipse.m2e.core.embedder.IMaven
;
import
org.eclipse.m2e.core.internal.IMavenConstants
;
import
org.eclipse.m2e.core.project.IMavenProjectFacade
;
import
org.eclipse.m2e.core.project.IMavenProjectRegistry
;
import
org.universaal.tools.packaging.tool.gui.GUI
;
import
org.universaal.tools.packaging.tool.util.POMParser
;
...
...
@@ -25,16 +32,47 @@ public class CreateJar {
String
destination_path
=
g
.
getTempDir
()+
"/bin/part"
+
partNumber
+
"/"
;
POMParser
p
=
new
POMParser
(
new
File
(
part
.
getFile
(
"pom.xml"
).
getLocation
()+
""
));
String
p
ath
=
part
.
getLocation
().
toString
();
//ResourcesPlugin.getWorkspace().getRoot().getLocation().makeAbsolute()+"/"+part.getDescription().getName();
String
sourceP
ath
=
part
.
getLocation
().
toString
();
//ResourcesPlugin.getWorkspace().getRoot().getLocation().makeAbsolute()+"/"+part.getDescription().getName();
try
{
String
fileName
=
p
.
getArtifactID
()+
"-"
+
p
.
getVersion
()+
".jar"
;
//
// Manifest manifest = new Manifest();
// manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
//
// JarOutputStream target = new JarOutputStream(new FileOutputStream(destination_path+fileName), manifest);
// add(new File(path), target, ResourcesPlugin.getWorkspace().getRoot().getLocation().makeAbsolute()+"/");
// target.close();
/* */
IMavenProjectRegistry
projectManager
=
MavenPlugin
.
getMavenProjectRegistry
();
IFile
pomResource
=
g
.
getPart
(
part
.
getName
()).
getFile
(
IMavenConstants
.
POM_FILE_NAME
);
IMavenProjectFacade
projectFacade
=
projectManager
.
create
(
pomResource
,
true
,
null
);
IMaven
maven
=
MavenPlugin
.
getMaven
();
if
(
pomResource
!=
null
&&
projectFacade
!=
null
){
MavenExecutionRequest
request
=
projectManager
.
createExecutionRequest
(
pomResource
,
projectFacade
.
getResolverConfiguration
(),
null
);
List
<
String
>
goals
=
new
ArrayList
<
String
>();
Properties
props
=
new
Properties
();
IWorkspace
workspace
=
ResourcesPlugin
.
getWorkspace
();
IWorkspaceDescription
description
=
workspace
.
getDescription
();
if
(!
description
.
isAutoBuilding
())
goals
.
add
(
"compiler:compile"
);
// compile it if autobuilding is off
goals
.
add
(
"package"
);
request
.
setGoals
(
goals
);
request
.
setUserProperties
(
props
);
MavenExecutionResult
execution_result
=
maven
.
execute
(
request
,
null
);
if
(
execution_result
.
getExceptions
()
!=
null
&&
!
execution_result
.
getExceptions
().
isEmpty
())
for
(
int
i
=
0
;
i
<
execution_result
.
getExceptions
().
size
();
i
++)
System
.
out
.
println
(
"\nERROR: "
+
execution_result
.
getExceptions
().
get
(
i
).
getMessage
());
copyFile
(
new
File
(
sourcePath
+
"/target/"
+
fileName
),
new
File
(
destination_path
+
fileName
));
}
/* */
Manifest
manifest
=
new
Manifest
();
manifest
.
getMainAttributes
().
put
(
Attributes
.
Name
.
MANIFEST_VERSION
,
"1.0"
);
JarOutputStream
target
=
new
JarOutputStream
(
new
FileOutputStream
(
destination_path
+
fileName
),
manifest
);
add
(
new
File
(
path
),
target
,
ResourcesPlugin
.
getWorkspace
().
getRoot
().
getLocation
().
makeAbsolute
()+
"/"
);
target
.
close
();
}
catch
(
Exception
ex
){
ex
.
printStackTrace
();
...
...
@@ -42,11 +80,11 @@ public class CreateJar {
try
{
//if file KAR is present, add it to partX folder
//String path = ResourcesPlugin.getWorkspace().getRoot().getLocation().makeAbsolute()+"/"+part.getDescription().getName();
//POMParser p = new POMParser(new File(part.getFile("pom.xml").getLocation()+""));
String
fileName
=
p
.
getArtifactID
()+
"-"
+
p
.
getVersion
()+
".kar"
;
File
kar
=
new
File
(
p
ath
+
"/target/"
+
fileName
);
File
kar
=
new
File
(
sourceP
ath
+
"/target/"
+
fileName
);
if
(
kar
.
exists
())
copyFile
(
kar
,
new
File
(
destination_path
+
fileName
));
}
...
...
@@ -55,57 +93,57 @@ public class CreateJar {
}
}
private
void
add
(
File
source
,
JarOutputStream
target
,
String
startFrom
){
BufferedInputStream
in
=
null
;
try
{
if
(
source
.
isDirectory
()){
String
name
=
source
.
getPath
().
replace
(
"\\"
,
"/"
);
name
=
name
.
replace
(
startFrom
,
""
);
if
(!
name
.
isEmpty
()){
if
(!
name
.
endsWith
(
"/"
))
name
+=
"/"
;
JarEntry
entry
=
new
JarEntry
(
name
);
entry
.
setTime
(
source
.
lastModified
());
target
.
putNextEntry
(
entry
);
target
.
closeEntry
();
}
for
(
File
nestedFile:
source
.
listFiles
())
add
(
nestedFile
,
target
,
startFrom
);
return
;
}
JarEntry
entry
=
new
JarEntry
(
source
.
getPath
().
replace
(
"\\"
,
"/"
).
replace
(
startFrom
,
""
));
entry
.
setTime
(
source
.
lastModified
());
target
.
putNextEntry
(
entry
);
in
=
new
BufferedInputStream
(
new
FileInputStream
(
source
));
byte
[]
buffer
=
new
byte
[
1024
];
while
(
true
)
{
int
count
=
in
.
read
(
buffer
);
if
(
count
==
-
1
)
break
;
target
.
write
(
buffer
,
0
,
count
);
}
target
.
closeEntry
();
}
catch
(
Exception
ex
){
ex
.
printStackTrace
();
}
finally
{
if
(
in
!=
null
)
try
{
in
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
//
private void add(File source, JarOutputStream target, String startFrom){
//
//
BufferedInputStream in = null;
//
try{
//
if (source.isDirectory()){
//
//
String name = source.getPath().replace("\\", "/");
//
name = name.replace(startFrom, "");
//
//
if (!name.isEmpty()){
//
//
if (!name.endsWith("/"))
//
name += "/";
//
//
JarEntry entry = new JarEntry(name);
//
entry.setTime(source.lastModified());
//
target.putNextEntry(entry);
//
target.closeEntry();
//
}
//
for (File nestedFile: source.listFiles())
//
add(nestedFile, target, startFrom);
//
return;
//
}
//
//
JarEntry entry = new JarEntry(source.getPath().replace("\\", "/").replace(startFrom, ""));
//
entry.setTime(source.lastModified());
//
target.putNextEntry(entry);
//
in = new BufferedInputStream(new FileInputStream(source));
//
//
byte[] buffer = new byte[1024];
//
while (true)
//
{
//
int count = in.read(buffer);
//
if (count == -1)
//
break;
//
target.write(buffer, 0, count);
//
}
//
target.closeEntry();
//
}
//
catch(Exception ex){
//
ex.printStackTrace();
//
}
//
finally{
//
if (in != null)
//
try {
//
in.close();
//
} catch (IOException e) {
//
e.printStackTrace();
//
}
//
}
//
}
private
void
copyFile
(
File
source
,
File
destination
){
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment