1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

added mingwrt packages and cleaned up the untar action a bit.

This commit is contained in:
Doug Schaefer 2010-01-14 23:59:39 +00:00
parent 6cf7f9a686
commit e3bc2d6767
4 changed files with 106 additions and 75 deletions

View file

@ -15,7 +15,9 @@ import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.Path;
@ -48,8 +50,9 @@ import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
*/
public class WascanaGenerator implements IApplication {
private static Version wascanaVersion = Version.parseVersion("1.0.0.0");
private static Version binutilsVersion = Version.parseVersion("2.20.0.0");
private static Version mingwrtVersion = Version.parseVersion("3.15.2.4");
private static Version wascanaVersion = Version.parseVersion("1.0.0.0");
private static final String REPO_NAME = "Wascana";
@ -61,6 +64,9 @@ public class WascanaGenerator implements IApplication {
private ILicense gpl30License;
private ILicense lgpl21License;
private ILicense pdLicense; // public domain
private List<IInstallableUnit> iuList = new ArrayList<IInstallableUnit>();
@Override
public Object start(IApplicationContext context) throws Exception {
@ -76,21 +82,21 @@ public class WascanaGenerator implements IApplication {
createRepos(repoDir);
loadLicenses();
// binutils
// tools
IInstallableUnit binutilsIU = createIU(
"wascana.binutils",
"Wascana MinGW binutils",
"Wascana MinGW Binutils",
binutilsVersion,
gpl30License,
null);
IInstallableUnit binutilsSrcIU = createIU(
"wascana.binutils.source",
"Wascana MinGW binutils source",
"Wascana MinGW Binutils Source",
binutilsVersion,
gpl30License,
null);
// toolchain
IInstallableUnit toolsIU = createCategory(
"wascana.tools",
"Wascana Tools",
@ -99,11 +105,28 @@ public class WascanaGenerator implements IApplication {
createRequiredCap(binutilsIU),
});
// sdks
IInstallableUnit mingwrtIU = createIU(
"wascana.mingwrt",
"Wascana MinGW Runtime",
mingwrtVersion,
pdLicense,
null);
IInstallableUnit mingwrtSrcIU = createIU(
"wascana.mingwrt.source",
"Wascana MinGW Runtime Source",
mingwrtVersion,
pdLicense,
null);
IInstallableUnit sdksIU = createCategory(
"wascana.sdks",
"Wascana SDKs",
wascanaVersion,
new IRequiredCapability[] {
createRequiredCap(mingwrtIU),
});
IInstallableUnit sourceIU = createCategory(
@ -112,6 +135,7 @@ public class WascanaGenerator implements IApplication {
wascanaVersion,
new IRequiredCapability[] {
createRequiredCap(binutilsSrcIU),
createRequiredCap(mingwrtSrcIU),
});
IInstallableUnit wascanaIU = createCategory(
@ -124,16 +148,7 @@ public class WascanaGenerator implements IApplication {
createRequiredCap(sourceIU),
});
metaRepo.addInstallableUnits(new IInstallableUnit[] {
binutilsIU,
binutilsSrcIU,
toolsIU,
sdksIU,
sourceIU,
wascanaIU
});
metaRepo.addInstallableUnits(iuList.toArray(new IInstallableUnit[iuList.size()]));
System.out.println("done");
@ -183,6 +198,7 @@ public class WascanaGenerator implements IApplication {
lgpl21License = MetadataFactory.createLicense(
new URI("http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"),
Activator.getFileContents(new Path("licenses/lgpl-2.1.txt")));
pdLicense = MetadataFactory.createLicense(null, "This package has no copyright assignment and is placed in the Public Domain.");
}
private InstallableUnitDescription createIUDesc(String id, String name, Version version, ILicense license) throws ProvisionException {
@ -217,7 +233,9 @@ public class WascanaGenerator implements IApplication {
ArtifactDescriptor artiDesc = new ArtifactDescriptor(artiKey);
artiRepo.addDescriptor(artiDesc);
iuDesc.setArtifacts(new IArtifactKey[] { artiKey });
return MetadataFactory.createInstallableUnit(iuDesc);
IInstallableUnit iu = MetadataFactory.createInstallableUnit(iuDesc);
iuList.add(iu);
return iu;
}
private IInstallableUnit createCategory(String id, String name, Version version,
@ -226,7 +244,9 @@ public class WascanaGenerator implements IApplication {
if (reqs != null)
iuDesc.setRequiredCapabilities(reqs);
iuDesc.setProperty(IInstallableUnit.PROP_TYPE_CATEGORY, String.valueOf(true));
return MetadataFactory.createInstallableUnit(iuDesc);
IInstallableUnit iu = MetadataFactory.createInstallableUnit(iuDesc);
iuList.add(iu);
return iu;
}
private IRequiredCapability createRequiredCap(IInstallableUnit iu) {

View file

@ -61,7 +61,7 @@ public class Activator extends Plugin {
return plugin;
}
static public BundleContext getContext() {
public static BundleContext getContext() {
return plugin.getBundle().getBundleContext();
}
@ -72,8 +72,8 @@ public class Activator extends Plugin {
* @return the service
*/
@SuppressWarnings("unchecked")
public <T> T getService(Class<T> clazz) {
BundleContext context = getBundle().getBundleContext();
public static <T> T getService(Class<T> clazz) {
BundleContext context = plugin.getBundle().getBundleContext();
ServiceReference ref = context.getServiceReference(clazz.getName());
return (ref != null) ? (T)context.getService(ref) : null;
}
@ -83,11 +83,11 @@ public class Activator extends Plugin {
*
* @param status
*/
public void log(int severity, String message, Throwable exception) {
public static void log(int severity, String message, Throwable exception) {
Platform.getLog(plugin.getBundle()).log(new Status(severity, PLUGIN_ID, message, exception));
}
public void log(IStatus status) {
public static void log(IStatus status) {
Platform.getLog(plugin.getBundle()).log(status);
}

View file

@ -14,6 +14,7 @@ import java.io.File;
import java.util.Map;
import java.util.StringTokenizer;
import org.eclipse.cdt.internal.p2.Activator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.engine.Profile;
@ -38,12 +39,20 @@ public class CleanupUntarAction extends ProvisioningAction {
@Override
public IStatus execute(Map parameters) {
return cleanup(parameters);
try {
return cleanup(parameters);
} catch (Exception e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e);
}
}
@Override
public IStatus undo(Map parameters) {
return UntarAction.untar(parameters);
try {
return UntarAction.untar(parameters);
} catch (Exception e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e);
}
}
public static IStatus cleanup(Map parameters) {

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.p2.touchpoint.natives.actions;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Map;
@ -22,6 +21,7 @@ import java.util.zip.GZIPInputStream;
import org.apache.tools.bzip2.CBZip2InputStream;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;
import org.eclipse.cdt.internal.p2.Activator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.engine.Profile;
@ -59,15 +59,23 @@ public class UntarAction extends ProvisioningAction {
@Override
public IStatus execute(Map parameters) {
return untar(parameters);
try {
return untar(parameters);
} catch (Exception e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e);
}
}
@Override
public IStatus undo(Map parameters) {
return CleanupUntarAction.cleanup(parameters);
try {
return CleanupUntarAction.cleanup(parameters);
} catch (Exception e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e);
}
}
public static IStatus untar(Map parameters) {
public static IStatus untar(Map parameters) throws Exception {
String source = (String)parameters.get(ActionConstants.PARM_SOURCE);
if (source == null)
return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_SOURCE, ACTION_NAME));
@ -120,7 +128,7 @@ public class UntarAction extends ProvisioningAction {
return Status.OK_STATUS;
}
private static File[] untar(String source, String destination, Compression compression) {
private static File[] untar(String source, String destination, Compression compression) throws Exception {
File zipFile = new File(source);
if (!zipFile.exists()) {
Util.log(UnzipAction.class.getName() + " the files to be unzipped is not here"); //$NON-NLS-1$
@ -128,53 +136,47 @@ public class UntarAction extends ProvisioningAction {
File target = new File(destination);
try {
FileInputStream fileIn = new FileInputStream(zipFile);
InputStream compIn = fileIn;
if (compression.equals(Compression.gz))
compIn = new GZIPInputStream(fileIn);
else if (compression.equals(Compression.bz2)) {
// Skip the magic bytes first
fileIn.read(new byte[2]);
compIn = new CBZip2InputStream(fileIn);
}
ArrayList<File> fileList = new ArrayList<File>();
TarInputStream tarIn = new TarInputStream(compIn);
for (TarEntry tarEntry = tarIn.getNextEntry(); tarEntry != null; tarEntry = tarIn.getNextEntry()) {
File outFile = new File(target, tarEntry.getName());
if (tarEntry.isDirectory()) {
outFile.mkdirs();
} else {
if (outFile.exists())
outFile.delete();
else
outFile.getParentFile().mkdirs();
FileOutputStream outStream = new FileOutputStream(outFile);
tarIn.copyEntryContents(outStream);
outStream.close();
// Set last modified time from the tar entry
long lastModified = tarEntry.getModTime().getTime();
outFile.setLastModified(lastModified);
// Set the executable bits from the tar entry
// we let the umask determine the r/w
int mode = tarEntry.getMode();
boolean exec = (mode & 0x111) != 0;
boolean execOwner = (mode & 0x11) == 0;
// outFile.setExecutable(exec, execOwner);
fileList.add(outFile);
}
}
tarIn.close();
return fileList.toArray(new File[fileList.size()]);
} catch (IOException e) {
Util.log(UnzipAction.class.getName() + " error unzipping zipfile: " + zipFile.getAbsolutePath() + " destination: " + destination); //$NON-NLS-1$ //$NON-NLS-2$
Util.log(e.getLocalizedMessage());
FileInputStream fileIn = new FileInputStream(zipFile);
InputStream compIn = fileIn;
if (compression.equals(Compression.gz))
compIn = new GZIPInputStream(fileIn);
else if (compression.equals(Compression.bz2)) {
// Skip the magic bytes first
fileIn.read(new byte[2]);
compIn = new CBZip2InputStream(fileIn);
}
return null;
ArrayList<File> fileList = new ArrayList<File>();
TarInputStream tarIn = new TarInputStream(compIn);
for (TarEntry tarEntry = tarIn.getNextEntry(); tarEntry != null; tarEntry = tarIn.getNextEntry()) {
File outFile = new File(target, tarEntry.getName());
if (tarEntry.isDirectory()) {
outFile.mkdirs();
} else {
if (outFile.exists())
outFile.delete();
else
outFile.getParentFile().mkdirs();
FileOutputStream outStream = new FileOutputStream(outFile);
tarIn.copyEntryContents(outStream);
outStream.close();
// Set last modified time from the tar entry
long lastModified = tarEntry.getModTime().getTime();
outFile.setLastModified(lastModified);
// Set the executable bits from the tar entry
// we let the umask determine the r/w
int mode = tarEntry.getMode();
boolean exec = (mode & 0x111) != 0;
boolean execOwner = (mode & 0x11) == 0;
// outFile.setExecutable(exec, execOwner);
fileList.add(outFile);
}
}
tarIn.close();
return fileList.toArray(new File[fileList.size()]);
}
}