mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Modernization and simplification of the p2 install plugins for CDT-base SDKs like Wascana. Now, we're simply provide untar as an action for the Eclipse native touchpoint. Updated the Wascana exemplary p2 repo generator to match
This commit is contained in:
parent
00f353d2c8
commit
fb77f8f0dc
23 changed files with 239 additions and 1538 deletions
|
@ -11,6 +11,7 @@ Require-Bundle: org.eclipse.core.runtime,
|
|||
org.eclipse.equinox.p2.metadata;bundle-version="1.0.0",
|
||||
org.eclipse.equinox.p2.engine;bundle-version="1.0.1",
|
||||
org.eclipse.equinox.p2.metadata.repository;bundle-version="1.0.0",
|
||||
org.eclipse.equinox.p2.metadata.generator;bundle-version="1.0.1"
|
||||
org.eclipse.equinox.p2.metadata.generator;bundle-version="1.0.1",
|
||||
org.eclipse.equinox.p2.publisher;bundle-version="1.0.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
|
|
|
@ -16,8 +16,6 @@ import java.net.URI;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.p2.internal.repo.artifact.InstallArtifactRepository;
|
||||
import org.eclipse.cdt.p2.internal.touchpoint.SDKTouchpoint;
|
||||
import org.eclipse.equinox.app.IApplication;
|
||||
import org.eclipse.equinox.app.IApplicationContext;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
|
||||
|
@ -31,12 +29,13 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
|
|||
import org.eclipse.equinox.internal.provisional.p2.metadata.ILicense;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IProvidedCapability;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IRequiredCapability;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointType;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IUpdateDescriptor;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.generator.MetadataGeneratorHelper;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
|
||||
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
/**
|
||||
|
@ -47,6 +46,12 @@ public class MinGWGenerator implements IApplication {
|
|||
|
||||
private static final String REPO_NAME = "Wascana";
|
||||
|
||||
private static final ITouchpointType NATIVE_TOUCHPOINT
|
||||
= MetadataFactory.createTouchpointType("org.eclipse.equinox.p2.native", new Version("1.0.0"));
|
||||
private static final String GZ_COMPRESSION = "gz";
|
||||
private static final String BZ2_COMPRESSION = "bz2";
|
||||
private static final String ZIP_COMPRESSION = "zip";
|
||||
|
||||
IMetadataRepository metaRepo;
|
||||
IArtifactRepository artiRepo;
|
||||
|
||||
|
@ -84,7 +89,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit runtimeIU = createIU(runtimeIUDesc, runtimeId, runtimeVersion,
|
||||
"http://downloads.sourceforge.net/mingw/mingwrt-3.15.1-mingw32.tar.gz",
|
||||
mingwSubdir,
|
||||
InstallArtifactRepository.GZIP_COMPRESSION);
|
||||
GZ_COMPRESSION);
|
||||
|
||||
// w32api
|
||||
String w32apiId = "wascana.mingw.w32api";
|
||||
|
@ -93,7 +98,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit w32apiIU = createIU(w32apiIUDesc, w32apiId, w32apiVersion,
|
||||
"http://downloads.sourceforge.net/mingw/w32api-3.13-mingw32-dev.tar.gz",
|
||||
mingwSubdir,
|
||||
InstallArtifactRepository.GZIP_COMPRESSION);
|
||||
GZ_COMPRESSION);
|
||||
|
||||
// binutils
|
||||
String binutilsId = "wascana.mingw.binutils";
|
||||
|
@ -102,7 +107,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit binutilsIU = createIU(binutilsIUDesc, binutilsId, binutilsVersion,
|
||||
"http://downloads.sourceforge.net/mingw/binutils-2.19-mingw32-bin.tar.gz",
|
||||
mingwSubdir,
|
||||
InstallArtifactRepository.GZIP_COMPRESSION);
|
||||
GZ_COMPRESSION);
|
||||
|
||||
// gcc-4 core
|
||||
String gcc4coreId = "wascana.mingw.gcc4.core";
|
||||
|
@ -123,7 +128,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit gcc4coreIU = createIU(gcc4coreIUDesc, gcc4coreId, gcc4Version,
|
||||
"http://downloads.sourceforge.net/tdm-gcc/gcc-4.3.2-tdm-1-core.tar.gz",
|
||||
mingwSubdir,
|
||||
InstallArtifactRepository.GZIP_COMPRESSION);
|
||||
GZ_COMPRESSION);
|
||||
|
||||
// gcc-4 g++
|
||||
String gcc4gppId = "wascana.mingw.gcc4.g++";
|
||||
|
@ -138,7 +143,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit gcc4gppIU = createIU(gcc4gppIUDesc, gcc4gppId, gcc4Version,
|
||||
"http://downloads.sourceforge.net/tdm-gcc/gcc-4.3.2-tdm-1-g++.tar.gz",
|
||||
mingwSubdir,
|
||||
InstallArtifactRepository.GZIP_COMPRESSION);
|
||||
GZ_COMPRESSION);
|
||||
|
||||
// gdb
|
||||
String gdbId = "wascana.mingw.gdb";
|
||||
|
@ -147,7 +152,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit gdbIU = createIU(gdbIUDesc, gdbId, gdbVersion,
|
||||
"http://downloads.sourceforge.net/mingw/gdb-6.8-mingw-3.tar.bz2",
|
||||
mingwSubdir,
|
||||
InstallArtifactRepository.BZIP2_COMPRESSION);
|
||||
BZ2_COMPRESSION);
|
||||
|
||||
// msys
|
||||
String msysId = "wascana.msys.core";
|
||||
|
@ -156,7 +161,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit msysIU = createIU(msysIUDesc, msysId, msysVersion,
|
||||
"http://downloads.sourceforge.net/mingw/msysCORE-1.0.11-20080826.tar.gz",
|
||||
"msys",
|
||||
InstallArtifactRepository.GZIP_COMPRESSION);
|
||||
GZ_COMPRESSION);
|
||||
|
||||
// MinGW toolchain category
|
||||
InstallableUnitDescription mingwToolchainDesc = createIUDesc("wascana.mingw", wascanaVersion, "MinGW Toolchain", null);;
|
||||
|
@ -180,7 +185,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit zlibIU = createIU(zlibIUDesc, zlibId, zlibVersion,
|
||||
"http://downloads.sourceforge.net/wascana/zlib-mingw-1.2.3.zip",
|
||||
mingwSubdir,
|
||||
InstallArtifactRepository.ZIP_COMPRESSION);
|
||||
ZIP_COMPRESSION);
|
||||
|
||||
// SDL
|
||||
String sdlId = "wascana.sdl";
|
||||
|
@ -189,7 +194,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit sdlIU = createIU(sdlIUDesc, sdlId, sdlVersion,
|
||||
"http://downloads.sourceforge.net/wascana/SDL-mingw-1.2.13.zip",
|
||||
mingwSubdir,
|
||||
InstallArtifactRepository.ZIP_COMPRESSION);
|
||||
ZIP_COMPRESSION);
|
||||
|
||||
// wxWidgets
|
||||
String wxId = "wascana.wxWidgets";
|
||||
|
@ -198,7 +203,7 @@ public class MinGWGenerator implements IApplication {
|
|||
IInstallableUnit wxIU = createIU(wxDesc, wxId, wxVersion,
|
||||
"http://downloads.sourceforge.net/wascana/wxMSW-mingw-2.8.9.zip",
|
||||
mingwSubdir,
|
||||
InstallArtifactRepository.ZIP_COMPRESSION);
|
||||
ZIP_COMPRESSION);
|
||||
|
||||
// Libraries toolchain category
|
||||
InstallableUnitDescription libsIUDesc = createIUDesc("wascana.libs", wascanaVersion, "Libraries", null);;
|
||||
|
@ -252,14 +257,23 @@ public class MinGWGenerator implements IApplication {
|
|||
|
||||
private IInstallableUnit createIU(InstallableUnitDescription iuDesc, String id, Version version, String location, String subdir, String compression) throws ProvisionException {
|
||||
iuDesc.setProperty(IInstallableUnit.PROP_TYPE_GROUP, Boolean.TRUE.toString());
|
||||
iuDesc.setTouchpointType(SDKTouchpoint.TOUCHPOINT_TYPE);
|
||||
iuDesc.setTouchpointType(NATIVE_TOUCHPOINT);
|
||||
Map<String, String> tpdata = new HashMap<String, String>();
|
||||
tpdata.put("uninstall", "uninstall()");
|
||||
|
||||
String cmd;
|
||||
if (compression.equals(ZIP_COMPRESSION)) {
|
||||
cmd = "unzip(source:@artifact, target:${installFolder}/" + subdir + ");";
|
||||
} else {
|
||||
cmd = "untar(source:@artifact, target:${installFolder}/" + subdir
|
||||
+ ", compression:" + compression + ");";
|
||||
}
|
||||
|
||||
tpdata.put("install", cmd);
|
||||
tpdata.put("install", "cleanup" + cmd);
|
||||
|
||||
iuDesc.addTouchpointData(MetadataFactory.createTouchpointData(tpdata));
|
||||
IArtifactKey artiKey = MetadataGeneratorHelper.createLauncherArtifactKey(id, version);
|
||||
IArtifactKey artiKey = PublisherHelper.createBinaryArtifactKey(id, version);
|
||||
ArtifactDescriptor artiDesc = new ArtifactDescriptor(artiKey);
|
||||
artiDesc.setProperty(InstallArtifactRepository.SUB_DIR, subdir);
|
||||
artiDesc.setProperty(InstallArtifactRepository.COMPRESSION, compression);
|
||||
artiDesc.setRepositoryProperty("artifact.reference", location);
|
||||
artiRepo.addDescriptor(artiDesc);
|
||||
iuDesc.setArtifacts(new IArtifactKey[] { artiKey });
|
||||
|
|
|
@ -3,16 +3,16 @@ Bundle-ManifestVersion: 2
|
|||
Bundle-Name: CDT P2 customizations for SDKs
|
||||
Bundle-SymbolicName: org.eclipse.cdt.p2;singleton:=true
|
||||
Bundle-Version: 5.0.0.qualifier
|
||||
Bundle-Activator: org.eclipse.cdt.p2.Activator
|
||||
Bundle-Activator: org.eclipse.cdt.internal.p2.Activator
|
||||
Bundle-Vendor: Eclipse.org
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.equinox.p2.artifact.repository;bundle-version="1.0.2",
|
||||
org.eclipse.equinox.p2.core;bundle-version="1.0.0",
|
||||
org.eclipse.equinox.p2.metadata;bundle-version="1.0.0",
|
||||
org.eclipse.equinox.p2.engine;bundle-version="1.0.1",
|
||||
org.apache.ant;bundle-version="1.7.0"
|
||||
org.apache.ant;bundle-version="1.7.0",
|
||||
org.eclipse.equinox.p2.touchpoint.natives;bundle-version="1.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.eclipse.cdt.p2,
|
||||
org.eclipse.cdt.p2.internal.repo.artifact;x-friends:="org.eclipse.cdt.p2.generator",
|
||||
org.eclipse.cdt.p2.internal.touchpoint;x-friends:="org.eclipse.cdt.p2.generator"
|
||||
Export-Package: org.eclipse.cdt.internal.p2,
|
||||
org.eclipse.cdt.internal.p2.touchpoint.natives.actions
|
||||
|
|
|
@ -2,30 +2,21 @@
|
|||
<?eclipse version="3.2"?>
|
||||
<plugin>
|
||||
<extension
|
||||
id="org.eclipse.cdt.p2.internal.repo.artifact.InstallArtifactRepository"
|
||||
name="%installArtifactRepository"
|
||||
point="org.eclipse.equinox.p2.artifact.repository.artifactRepositories">
|
||||
<factory
|
||||
class="org.eclipse.cdt.p2.internal.repo.artifact.InstallArtifactRepositoryFactory">
|
||||
</factory>
|
||||
<filter
|
||||
suffix="installArtifact.xml">
|
||||
</filter>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.equinox.p2.engine.touchpoints">
|
||||
<touchpoint
|
||||
class="org.eclipse.cdt.p2.internal.touchpoint.SDKTouchpoint"
|
||||
type="org.eclipse.cdt.p2.internal.touchpoint.SDKTouchpoint"
|
||||
point="org.eclipse.equinox.p2.engine.actions">
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.p2.touchpoint.natives.actions.UntarAction"
|
||||
name="untar"
|
||||
touchpointType="org.eclipse.equinox.p2.native"
|
||||
touchpointVersion="1.0.0"
|
||||
version="1.0.0">
|
||||
</touchpoint>
|
||||
</action>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.equinox.p2.engine.actions">
|
||||
<action
|
||||
class="org.eclipse.cdt.p2.internal.touchpoint.ExtractAction"
|
||||
name="extract"
|
||||
touchpointType="org.eclipse.cdt.p2.internal.touchpoint.SDKTouchpoint"
|
||||
class="org.eclipse.cdt.internal.p2.touchpoint.natives.actions.CleanupUntarAction"
|
||||
name="cleanupuntar"
|
||||
touchpointType="org.eclipse.equinox.p2.native"
|
||||
touchpointVersion="1.0.0"
|
||||
version="1.0.0">
|
||||
</action>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.eclipse.cdt.p2;
|
||||
package org.eclipse.cdt.internal.p2;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
|
@ -0,0 +1,33 @@
|
|||
package org.eclipse.cdt.internal.p2.touchpoint.natives.actions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CleanupzipAction;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
|
||||
|
||||
/**
|
||||
* Cleanup an untared artifact.
|
||||
*
|
||||
* syntax: cleanupuntar(source:@artifact, target:${installFolder}/<subdir>, compression:[gz|bz2])
|
||||
*
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class CleanupUntarAction extends ProvisioningAction {
|
||||
|
||||
@Override
|
||||
public IStatus execute(Map parameters) {
|
||||
return cleanup(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus undo(Map parameters) {
|
||||
return UntarAction.untar(parameters);
|
||||
}
|
||||
|
||||
public static IStatus cleanup(Map parameters) {
|
||||
return CleanupzipAction.cleanupzip(parameters);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
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;
|
||||
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.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.equinox.internal.p2.engine.Profile;
|
||||
import org.eclipse.equinox.internal.p2.touchpoint.natives.Messages;
|
||||
import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
|
||||
import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.ActionConstants;
|
||||
import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.UnzipAction;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IFileArtifactRepository;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* Untar the artifact with a choice of compression
|
||||
*
|
||||
* syntax: untar(source:@artifact, target:${installFolder}/<subdir>, compression:[gz|bz2])
|
||||
*
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class UntarAction extends ProvisioningAction {
|
||||
|
||||
private static final String ACTION_NAME = "untar";
|
||||
private static final String PARM_COMPRESSION = "compression";
|
||||
private static final String VALUE_GZ = "gz";
|
||||
private static final String VALUE_BZ2 = "bz2";
|
||||
|
||||
private enum Compression {
|
||||
none,
|
||||
gz,
|
||||
bz2
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus execute(Map parameters) {
|
||||
return untar(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus undo(Map parameters) {
|
||||
return CleanupUntarAction.cleanup(parameters);
|
||||
}
|
||||
|
||||
public static IStatus untar(Map parameters) {
|
||||
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));
|
||||
|
||||
String originalSource = source;
|
||||
String target = (String)parameters.get(ActionConstants.PARM_TARGET);
|
||||
if (target == null)
|
||||
return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET, ACTION_NAME));
|
||||
|
||||
String compressionStr = (String)parameters.get(PARM_COMPRESSION);
|
||||
Compression compression;
|
||||
if (compressionStr == null)
|
||||
return Util.createError(NLS.bind(Messages.param_not_set, PARM_COMPRESSION, ACTION_NAME));
|
||||
else if (compressionStr.equals(VALUE_GZ))
|
||||
compression = Compression.gz;
|
||||
else if (compressionStr.equals(VALUE_BZ2))
|
||||
compression = Compression.bz2;
|
||||
else
|
||||
// TODO Should put out a log if compression is unknown
|
||||
compression = Compression.none;
|
||||
|
||||
IInstallableUnit iu = (IInstallableUnit) parameters.get(ActionConstants.PARM_IU);
|
||||
Profile profile = (Profile) parameters.get(ActionConstants.PARM_PROFILE);
|
||||
|
||||
if (source.equals(ActionConstants.PARM_ARTIFACT)) {
|
||||
//TODO: fix wherever this occurs -- investigate as this is probably not desired
|
||||
if (iu.getArtifacts() == null || iu.getArtifacts().length == 0)
|
||||
return Status.OK_STATUS;
|
||||
|
||||
IArtifactKey artifactKey = iu.getArtifacts()[0];
|
||||
|
||||
IFileArtifactRepository downloadCache;
|
||||
try {
|
||||
downloadCache = Util.getDownloadCacheRepo();
|
||||
} catch (ProvisionException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
File fileLocation = downloadCache.getArtifactFile(artifactKey);
|
||||
if ((fileLocation == null) || !fileLocation.exists())
|
||||
return Util.createError(NLS.bind(Messages.artifact_not_available, artifactKey));
|
||||
source = fileLocation.getAbsolutePath();
|
||||
}
|
||||
|
||||
File[] unzippedFiles = untar(source, target, compression);
|
||||
StringBuffer unzippedFileNameBuffer = new StringBuffer();
|
||||
for (int i = 0; i < unzippedFiles.length; i++)
|
||||
unzippedFileNameBuffer.append(unzippedFiles[i].getAbsolutePath()).append(ActionConstants.PIPE);
|
||||
|
||||
profile.setInstallableUnitProperty(iu, "unzipped" + ActionConstants.PIPE + originalSource + ActionConstants.PIPE + target, unzippedFileNameBuffer.toString()); //$NON-NLS-1$
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
private static File[] untar(String source, String destination, Compression compression) {
|
||||
File zipFile = new File(source);
|
||||
if (zipFile == null || !zipFile.exists()) {
|
||||
Util.log(UnzipAction.class.getName() + " the files to be unzipped is not here"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
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(source, 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();
|
||||
long lastModified = tarEntry.getModTime().getTime();
|
||||
outFile.setLastModified(lastModified);
|
||||
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$
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class FileListReader {
|
||||
|
||||
private final BufferedReader in;
|
||||
|
||||
public FileListReader(File fileListfile) throws IOException {
|
||||
in = new BufferedReader(new FileReader(fileListfile));
|
||||
}
|
||||
|
||||
public InstalledFile getNext() throws IOException {
|
||||
String line = in.readLine();
|
||||
return line != null ? new InstalledFile(line) : null;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
in.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FileListWriter {
|
||||
|
||||
private final BufferedWriter out;
|
||||
|
||||
public FileListWriter(File fileListFile) throws IOException {
|
||||
out = new BufferedWriter(new FileWriter(fileListFile));
|
||||
}
|
||||
|
||||
public void addFile(InstalledFile file) throws IOException {
|
||||
file.write(out);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
out.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,311 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.p2.Activator;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.equinox.internal.p2.core.helpers.URLUtil;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
|
||||
import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.AbstractArtifactRepository;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class InstallArtifactRepository extends AbstractArtifactRepository {
|
||||
|
||||
// Install directory property
|
||||
public static final String INSTALL_DIR = "installDir"; //$NON-NLS-1$
|
||||
public static final String SUB_DIR = "subdir"; //$NON-NLS-1$
|
||||
public static final String FILENAME = "installArtifact.xml"; //$NON-NLS-1$
|
||||
|
||||
public static final String COMPRESSION = "compression";
|
||||
public static final String GZIP_COMPRESSION = "tar.gz";
|
||||
public static final String BZIP2_COMPRESSION = "tar.bz2";
|
||||
public static final String ZIP_COMPRESSION = "zip";
|
||||
|
||||
private static final String VERSION = "2.0.0"; //$NON-NLS-1$
|
||||
private static final String DESCRIPTION = "Wind River Metadata Repository"; //$NON-NLS-1$
|
||||
private static final String PROVIDER = "Wind River"; //$NON-NLS-1$
|
||||
|
||||
// Map from artifact id to artifact descriptor. We only allow one version of each artifact
|
||||
// to be installed at a time.
|
||||
private Map<String, IArtifactDescriptor> artifacts = new HashMap<String, IArtifactDescriptor>();
|
||||
|
||||
public InstallArtifactRepository(URI aLocation, String aName, Map aProperties) {
|
||||
super(aName, InstallArtifactRepository.class.getName(), VERSION, aLocation, DESCRIPTION, PROVIDER, aProperties);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for reading in from file.
|
||||
*
|
||||
* @param _name
|
||||
* @param _type
|
||||
* @param _version
|
||||
* @param _description
|
||||
* @param _provider
|
||||
* @param _artifacts
|
||||
* @param mappingRules
|
||||
* @param _properties
|
||||
*/
|
||||
InstallArtifactRepository(String _name, String _type, String _version, URI _location, String _description, String _provider, Set<ArtifactDescriptor> _artifacts, Map _properties) {
|
||||
super(_name, _type, _version, _location, _description, _provider, _properties);
|
||||
for (IArtifactDescriptor descriptor : _artifacts)
|
||||
artifacts.put(descriptor.getArtifactKey().getId(), descriptor);
|
||||
}
|
||||
|
||||
public static URI getActualLocation(URI base) {
|
||||
final String name = FILENAME;
|
||||
String spec = base.toString();
|
||||
if (spec.endsWith(name))
|
||||
return base;
|
||||
if (spec.endsWith("/")) //$NON-NLS-1$
|
||||
spec += name;
|
||||
else
|
||||
spec += "/" + name; //$NON-NLS-1$
|
||||
try {
|
||||
return new URI(spec);
|
||||
} catch (URISyntaxException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static IArtifactRepository getRepository(IProfile profile) throws ProvisionException {
|
||||
AgentLocation location = Activator.getDefault().getService(AgentLocation.class);
|
||||
String profileId = profile.getProfileId();
|
||||
profileId = profileId.replaceAll("[:/\\\\]", "_"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
try {
|
||||
URL url = location.getDataArea(Activator.PLUGIN_ID);
|
||||
URI uri = new URI(url.toExternalForm() + "installDirRepo/" + profileId + "/" + FILENAME); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
IArtifactRepositoryManager repoMgr = Activator.getDefault().getService(IArtifactRepositoryManager.class);
|
||||
try {
|
||||
return repoMgr.loadRepository(uri, null);
|
||||
} catch (ProvisionException e) {
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put(INSTALL_DIR, profile.getLocalProperty(IProfile.PROP_INSTALL_FOLDER));
|
||||
return repoMgr.createRepository(uri, profile.getProfileId(), InstallArtifactRepository.class.getName(), properties);
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
Activator.getDefault().log(IStatus.ERROR, "Creating install repo URI", e); //$NON-NLS-1$
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModifiable() {
|
||||
// We're always modifiable
|
||||
// TODO - unless we're a shared install...
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IArtifactDescriptor descriptor) {
|
||||
return contains(descriptor.getArtifactKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean contains(IArtifactKey key) {
|
||||
IArtifactDescriptor desc = artifacts.get(key.getId());
|
||||
if (desc == null)
|
||||
return false;
|
||||
return desc.getArtifactKey().equals(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus getArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) {
|
||||
// copying from this repository is not supported, yet...
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) {
|
||||
// we only have one artifact descriptor per key
|
||||
IArtifactDescriptor desc = artifacts.get(key);
|
||||
if (desc != null)
|
||||
return new IArtifactDescriptor[] { desc };
|
||||
return new IArtifactDescriptor[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized IArtifactKey[] getArtifactKeys() {
|
||||
Collection<IArtifactDescriptor> descs = artifacts.values();
|
||||
IArtifactKey[] keys = new IArtifactKey[descs.size()];
|
||||
int i = 0;
|
||||
for (IArtifactDescriptor desc : descs)
|
||||
keys[i++] = desc.getArtifactKey();
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void addDescriptor(IArtifactDescriptor descriptor) {
|
||||
super.addDescriptor(descriptor);
|
||||
artifacts.put(descriptor.getArtifactKey().getId(), descriptor);
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void addDescriptors(IArtifactDescriptor[] descriptors) {
|
||||
super.addDescriptors(descriptors);
|
||||
for (IArtifactDescriptor descriptor : descriptors)
|
||||
artifacts.put(descriptor.getArtifactKey().getId(), descriptor);
|
||||
save();
|
||||
}
|
||||
|
||||
synchronized Collection<IArtifactDescriptor> getDescriptors() {
|
||||
return artifacts.values();
|
||||
}
|
||||
|
||||
private File getFileListFile(String artifact) throws IOException {
|
||||
File file = new File(location);
|
||||
if (file.getName().equals(FILENAME))
|
||||
file = file.getParentFile();
|
||||
return new File(file, artifact + ".txt"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException {
|
||||
// Add the descriptor to the list and save it
|
||||
IArtifactDescriptor oldDesc = artifacts.get(descriptor.getArtifactKey().getId());
|
||||
if (oldDesc != null)
|
||||
removeDescriptor(oldDesc);
|
||||
addDescriptor(descriptor);
|
||||
|
||||
// Start the extractor
|
||||
try {
|
||||
String installDirName = (String)getProperties().get(INSTALL_DIR);
|
||||
if (installDirName == null)
|
||||
throw new ProvisionException("Install directory not set"); //$NON-NLS-1$
|
||||
File installDir = new File(installDirName);
|
||||
String subDir = (String)descriptor.getProperties().get(SUB_DIR);
|
||||
if (subDir != null)
|
||||
installDir = new File(installDir, subDir);
|
||||
PipedOutputStream out = new PipedOutputStream();
|
||||
PipedInputStream in = new PipedInputStream(out);
|
||||
String compression = descriptor.getProperty(COMPRESSION);
|
||||
if (ZIP_COMPRESSION.equals(compression)) {
|
||||
ZipExtractor extractor = new ZipExtractor(in, installDir,
|
||||
new FileListWriter(getFileListFile(descriptor.getArtifactKey().getId())));
|
||||
extractor.start();
|
||||
} else {
|
||||
TarExtractor extractor = new TarExtractor(in, installDir,
|
||||
new FileListWriter(getFileListFile(descriptor.getArtifactKey().getId())),
|
||||
compression);
|
||||
extractor.start();
|
||||
}
|
||||
return out;
|
||||
} catch (IOException e) {
|
||||
// TODO How could that happen
|
||||
throw new ProvisionException(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteFiles(String artifact) {
|
||||
File fileListFile = null;
|
||||
try {
|
||||
fileListFile = getFileListFile(artifact);
|
||||
FileListReader reader = new FileListReader(fileListFile);
|
||||
InstalledFile file;
|
||||
while ((file = reader.getNext()) != null) {
|
||||
file.uninstall();
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
Activator.getDefault().log(IStatus.WARNING, "deleting file", e); //$NON-NLS-1$
|
||||
} finally {
|
||||
if (fileListFile != null)
|
||||
fileListFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeAll() {
|
||||
super.removeAll();
|
||||
for (String artifact : artifacts.keySet())
|
||||
deleteFiles(artifact);
|
||||
artifacts.clear();
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDescriptor(IArtifactDescriptor descriptor) {
|
||||
removeDescriptor(descriptor.getArtifactKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeDescriptor(IArtifactKey key) {
|
||||
super.removeDescriptor(key);
|
||||
deleteFiles(key.getId());
|
||||
artifacts.remove(key);
|
||||
save();
|
||||
}
|
||||
|
||||
private void save() {
|
||||
try {
|
||||
OutputStream os = null;
|
||||
try {
|
||||
URI actualLocation = getActualLocation(location);
|
||||
File artifactsFile = new File(actualLocation);
|
||||
artifactsFile.getParentFile().mkdirs();
|
||||
os = new FileOutputStream(artifactsFile);
|
||||
super.setProperty(IRepository.PROP_TIMESTAMP, Long.toString(System.currentTimeMillis()));
|
||||
new InstallArtifactRepositoryIO().write(this, os);
|
||||
} catch (IOException e) {
|
||||
// TODO proper exception handling
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (os != null)
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public IStatus getRawArtifact(IArtifactDescriptor descriptor,
|
||||
OutputStream destination, IProgressMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.p2.Activator;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
|
||||
import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class InstallArtifactRepositoryFactory extends ArtifactRepositoryFactory {
|
||||
|
||||
public IArtifactRepository create(URI location, String name, String type, Map properties) throws ProvisionException {
|
||||
return new InstallArtifactRepository(location, name, properties);
|
||||
}
|
||||
|
||||
public IArtifactRepository load(URI location, IProgressMonitor monitor) throws ProvisionException {
|
||||
File localFile = null;
|
||||
boolean local = false;
|
||||
try {
|
||||
localFile = new File(InstallArtifactRepository.getActualLocation(location).getPath());
|
||||
InputStream descriptorStream = null;
|
||||
try {
|
||||
descriptorStream = new BufferedInputStream(new FileInputStream(localFile));
|
||||
InstallArtifactRepositoryIO io = new InstallArtifactRepositoryIO();
|
||||
return io.read(localFile.toURI(), descriptorStream);
|
||||
} finally {
|
||||
if (descriptorStream != null)
|
||||
descriptorStream.close();
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
String msg = NLS.bind(Messages.io_failedRead, location);
|
||||
throw new ProvisionException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ProvisionException.REPOSITORY_NOT_FOUND, msg, e));
|
||||
} catch (IOException e) {
|
||||
String msg = NLS.bind(Messages.io_failedRead, location);
|
||||
throw new ProvisionException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e));
|
||||
} finally {
|
||||
// TODO why is this here?
|
||||
if (!local && localFile != null && !localFile.delete())
|
||||
localFile.deleteOnExit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,479 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.eclipse.cdt.p2.Activator;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties;
|
||||
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
|
||||
import org.eclipse.equinox.internal.p2.persistence.XMLParser;
|
||||
import org.eclipse.equinox.internal.p2.persistence.XMLWriter;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.Version;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.VersionRange;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class InstallArtifactRepositoryIO {
|
||||
|
||||
/**
|
||||
* Writes the given artifact repository to the stream.
|
||||
* This method performs buffering, and closes the stream when finished.
|
||||
*/
|
||||
public void write(InstallArtifactRepository repository, OutputStream output) {
|
||||
OutputStream bufferedOutput = null;
|
||||
try {
|
||||
try {
|
||||
bufferedOutput = new BufferedOutputStream(output);
|
||||
Writer repositoryWriter = new Writer(bufferedOutput);
|
||||
repositoryWriter.write(repository);
|
||||
} finally {
|
||||
if (bufferedOutput != null) {
|
||||
bufferedOutput.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
// TODO shouldn't this throw a core exception?
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the artifact repository from the given stream,
|
||||
* and returns the contained array of abstract artifact repositories.
|
||||
*
|
||||
* This method performs buffering, and closes the stream when finished.
|
||||
*/
|
||||
public IArtifactRepository read(URI location, InputStream input) throws ProvisionException {
|
||||
BufferedInputStream bufferedInput = null;
|
||||
try {
|
||||
try {
|
||||
bufferedInput = new BufferedInputStream(input);
|
||||
Parser repositoryParser = new Parser(Activator.getContext(), Activator.PLUGIN_ID, location);
|
||||
repositoryParser.parse(input);
|
||||
IStatus result = repositoryParser.getStatus();
|
||||
switch (result.getSeverity()) {
|
||||
case IStatus.CANCEL :
|
||||
throw new OperationCanceledException();
|
||||
case IStatus.ERROR :
|
||||
throw new ProvisionException(result);
|
||||
case IStatus.WARNING :
|
||||
case IStatus.INFO :
|
||||
Activator.getDefault().log(result);
|
||||
}
|
||||
return repositoryParser.getRepository();
|
||||
} finally {
|
||||
if (bufferedInput != null)
|
||||
bufferedInput.close();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
String msg = NLS.bind(Messages.io_failedRead, location);
|
||||
throw new ProvisionException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ProvisionException.REPOSITORY_FAILED_READ, msg, ioe));
|
||||
}
|
||||
}
|
||||
|
||||
private interface XMLConstants extends org.eclipse.equinox.internal.p2.persistence.XMLConstants {
|
||||
|
||||
// Constants defining the structure of the XML for a InstallArtifactRepository
|
||||
|
||||
// A format version number for simple artifact repository XML.
|
||||
public static final Version CURRENT_VERSION = new Version(1, 0, 0);
|
||||
public static final VersionRange XML_TOLERANCE = new VersionRange(CURRENT_VERSION, true, new Version(2, 0, 0), false);
|
||||
|
||||
// Constants for processing instructions
|
||||
public static final String PI_REPOSITORY_TARGET = "artifactRepository"; //$NON-NLS-1$
|
||||
public static XMLWriter.ProcessingInstruction[] PI_DEFAULTS = new XMLWriter.ProcessingInstruction[] {XMLWriter.ProcessingInstruction.makeClassVersionInstruction(PI_REPOSITORY_TARGET, InstallArtifactRepository.class, CURRENT_VERSION)};
|
||||
|
||||
// Constants for artifact repository elements
|
||||
public static final String REPOSITORY_ELEMENT = "repository"; //$NON-NLS-1$
|
||||
public static final String REPOSITORY_PROPERTIES_ELEMENT = "repositoryProperties"; //$NON-NLS-1$
|
||||
public static final String MAPPING_RULES_ELEMENT = "mappings"; //$NON-NLS-1$
|
||||
public static final String MAPPING_RULE_ELEMENT = "rule"; //$NON-NLS-1$
|
||||
public static final String ARTIFACTS_ELEMENT = "artifacts"; //$NON-NLS-1$
|
||||
public static final String ARTIFACT_ELEMENT = "artifact"; //$NON-NLS-1$
|
||||
public static final String PROCESSING_STEPS_ELEMENT = "processing"; //$NON-NLS-1$
|
||||
public static final String PROCESSING_STEP_ELEMENT = "step"; //$NON-NLS-1$
|
||||
|
||||
public static final String MAPPING_RULE_FILTER_ATTRIBUTE = "filter"; //$NON-NLS-1$
|
||||
public static final String MAPPING_RULE_OUTPUT_ATTRIBUTE = "output"; //$NON-NLS-1$
|
||||
|
||||
public static final String ARTIFACT_CLASSIFIER_ATTRIBUTE = CLASSIFIER_ATTRIBUTE;
|
||||
|
||||
public static final String STEP_DATA_ATTRIBUTE = "data"; //$NON-NLS-1$
|
||||
public static final String STEP_REQUIRED_ATTRIBUTE = "required"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
// XML writer for a InstallArtifactRepository
|
||||
protected class Writer extends XMLWriter implements XMLConstants {
|
||||
|
||||
public Writer(OutputStream output) throws IOException {
|
||||
super(output, PI_DEFAULTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the given artifact repository to the output stream.
|
||||
*/
|
||||
public void write(InstallArtifactRepository repository) {
|
||||
start(REPOSITORY_ELEMENT);
|
||||
attribute(NAME_ATTRIBUTE, repository.getName());
|
||||
attribute(TYPE_ATTRIBUTE, repository.getType());
|
||||
attribute(VERSION_ATTRIBUTE, repository.getVersion());
|
||||
attributeOptional(PROVIDER_ATTRIBUTE, repository.getProvider());
|
||||
attributeOptional(DESCRIPTION_ATTRIBUTE, repository.getDescription()); // TODO: could be cdata?
|
||||
|
||||
writeProperties(repository.getProperties());
|
||||
writeArtifacts(repository.getDescriptors());
|
||||
|
||||
end(REPOSITORY_ELEMENT);
|
||||
flush();
|
||||
}
|
||||
|
||||
private void writeArtifacts(Collection<IArtifactDescriptor> artifactDescriptors) {
|
||||
start(ARTIFACTS_ELEMENT);
|
||||
attribute(COLLECTION_SIZE_ATTRIBUTE, artifactDescriptors.size());
|
||||
for (IArtifactDescriptor idescriptor : artifactDescriptors) {
|
||||
ArtifactDescriptor descriptor = (ArtifactDescriptor)idescriptor;
|
||||
IArtifactKey key = descriptor.getArtifactKey();
|
||||
start(ARTIFACT_ELEMENT);
|
||||
attribute(ARTIFACT_CLASSIFIER_ATTRIBUTE, key.getClassifier());
|
||||
attribute(ID_ATTRIBUTE, key.getId());
|
||||
attribute(VERSION_ATTRIBUTE, key.getVersion());
|
||||
writeProcessingSteps(descriptor.getProcessingSteps());
|
||||
writeProperties(descriptor.getProperties());
|
||||
writeProperties(REPOSITORY_PROPERTIES_ELEMENT, descriptor.getRepositoryProperties());
|
||||
end(ARTIFACT_ELEMENT);
|
||||
}
|
||||
end(ARTIFACTS_ELEMENT);
|
||||
}
|
||||
|
||||
private void writeProcessingSteps(ProcessingStepDescriptor[] processingSteps) {
|
||||
if (processingSteps.length > 0) {
|
||||
start(PROCESSING_STEPS_ELEMENT);
|
||||
attribute(COLLECTION_SIZE_ATTRIBUTE, processingSteps.length);
|
||||
for (int i = 0; i < processingSteps.length; i++) {
|
||||
start(PROCESSING_STEP_ELEMENT);
|
||||
attribute(ID_ATTRIBUTE, processingSteps[i].getProcessorId());
|
||||
attribute(STEP_DATA_ATTRIBUTE, processingSteps[i].getData());
|
||||
attribute(STEP_REQUIRED_ATTRIBUTE, processingSteps[i].isRequired());
|
||||
end(PROCESSING_STEP_ELEMENT);
|
||||
}
|
||||
end(PROCESSING_STEPS_ELEMENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Parser for the contents of a InstallArtifactRepository,
|
||||
* as written by the Writer class.
|
||||
*/
|
||||
private class Parser extends XMLParser implements XMLConstants {
|
||||
|
||||
private InstallArtifactRepository theRepository;
|
||||
final URI location;
|
||||
|
||||
public Parser(BundleContext _context, String _bundleId, URI _location) {
|
||||
super(_context, _bundleId);
|
||||
location = _location;
|
||||
}
|
||||
|
||||
public void parse(File file) throws IOException {
|
||||
parse(new FileInputStream(file));
|
||||
}
|
||||
|
||||
public synchronized void parse(InputStream stream) throws IOException {
|
||||
this.status = null;
|
||||
try {
|
||||
// TODO: currently not caching the parser since we make no assumptions
|
||||
// or restrictions on concurrent parsing
|
||||
getParser();
|
||||
RepositoryHandler repositoryHandler = new RepositoryHandler();
|
||||
xmlReader.setContentHandler(new RepositoryDocHandler(REPOSITORY_ELEMENT, repositoryHandler));
|
||||
xmlReader.parse(new InputSource(stream));
|
||||
if (isValidXML()) {
|
||||
theRepository = repositoryHandler.getRepository();
|
||||
}
|
||||
} catch (SAXException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
public InstallArtifactRepository getRepository() {
|
||||
return theRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getRootObject() {
|
||||
return theRepository;
|
||||
}
|
||||
|
||||
private final class RepositoryDocHandler extends DocHandler {
|
||||
|
||||
public RepositoryDocHandler(String rootName, RootHandler rootHandler) {
|
||||
super(rootName, rootHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processingInstruction(String target, String data) throws SAXException {
|
||||
if (PI_REPOSITORY_TARGET.equals(target)) {
|
||||
// TODO: should the root handler be constructed based on class
|
||||
// via an extension registry mechanism?
|
||||
// String clazz = extractPIClass(data);
|
||||
// TODO: version tolerance by extension
|
||||
Version repositoryVersion = extractPIVersion(target, data);
|
||||
if (!XML_TOLERANCE.isIncluded(repositoryVersion)) {
|
||||
throw new SAXException(NLS.bind(Messages.io_incompatibleVersion, repositoryVersion, XML_TOLERANCE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final class RepositoryHandler extends RootHandler {
|
||||
|
||||
private final String[] required = new String[] {NAME_ATTRIBUTE, TYPE_ATTRIBUTE, VERSION_ATTRIBUTE};
|
||||
private final String[] optional = new String[] {DESCRIPTION_ATTRIBUTE, PROVIDER_ATTRIBUTE};
|
||||
|
||||
private String[] attrValues = new String[required.length + optional.length];
|
||||
|
||||
private PropertiesHandler propertiesHandler = null;
|
||||
private ArtifactsHandler artifactsHandler = null;
|
||||
|
||||
private InstallArtifactRepository repository = null;
|
||||
|
||||
public RepositoryHandler() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InstallArtifactRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleRootAttributes(Attributes attributes) {
|
||||
attrValues = parseAttributes(attributes, required, optional);
|
||||
attrValues[2] = checkVersion(REPOSITORY_ELEMENT, VERSION_ATTRIBUTE, attrValues[2]).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String name, Attributes attributes) {
|
||||
if (ARTIFACTS_ELEMENT.equals(name)) {
|
||||
if (artifactsHandler == null) {
|
||||
artifactsHandler = new ArtifactsHandler(this, attributes);
|
||||
} else {
|
||||
duplicateElement(this, name, attributes);
|
||||
}
|
||||
} else if (PROPERTIES_ELEMENT.equals(name)) {
|
||||
if (propertiesHandler == null) {
|
||||
propertiesHandler = new PropertiesHandler(this, attributes);
|
||||
} else {
|
||||
duplicateElement(this, name, attributes);
|
||||
}
|
||||
} else {
|
||||
invalidElement(name, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finished() {
|
||||
if (isValidXML()) {
|
||||
Map properties = (propertiesHandler == null ? new OrderedProperties(0) //
|
||||
: propertiesHandler.getProperties());
|
||||
Set<ArtifactDescriptor> artifacts = (artifactsHandler == null ? new HashSet<ArtifactDescriptor>(0) //
|
||||
: artifactsHandler.getArtifacts());
|
||||
repository = new InstallArtifactRepository(
|
||||
attrValues[0], attrValues[1], attrValues[2], Parser.this.location,
|
||||
attrValues[3], attrValues[4], artifacts, properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class ArtifactsHandler extends AbstractHandler {
|
||||
|
||||
private Set<ArtifactDescriptor> artifacts;
|
||||
|
||||
public ArtifactsHandler(AbstractHandler _parentHandler, Attributes attributes) {
|
||||
super(_parentHandler, ARTIFACTS_ELEMENT);
|
||||
String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE);
|
||||
artifacts = (size != null ? new LinkedHashSet<ArtifactDescriptor>(new Integer(size).intValue()) : new LinkedHashSet<ArtifactDescriptor>(4));
|
||||
}
|
||||
|
||||
public Set<ArtifactDescriptor> getArtifacts() {
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String name, Attributes attributes) {
|
||||
if (name.equals(ARTIFACT_ELEMENT)) {
|
||||
new ArtifactHandler(this, attributes, artifacts);
|
||||
} else {
|
||||
invalidElement(name, attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class ArtifactHandler extends AbstractHandler {
|
||||
|
||||
private final String[] required = new String[] {ARTIFACT_CLASSIFIER_ATTRIBUTE, ID_ATTRIBUTE, VERSION_ATTRIBUTE};
|
||||
|
||||
private Set<ArtifactDescriptor> artifacts;
|
||||
ArtifactDescriptor currentArtifact = null;
|
||||
|
||||
private PropertiesHandler propertiesHandler = null;
|
||||
private PropertiesHandler repositoryPropertiesHandler = null;
|
||||
private ProcessingStepsHandler processingStepsHandler = null;
|
||||
|
||||
public ArtifactHandler(AbstractHandler _parentHandler, Attributes attributes, Set<ArtifactDescriptor> _artifacts) {
|
||||
super(_parentHandler, ARTIFACT_ELEMENT);
|
||||
this.artifacts = _artifacts;
|
||||
String[] values = parseRequiredAttributes(attributes, required);
|
||||
Version version = checkVersion(ARTIFACT_ELEMENT, VERSION_ATTRIBUTE, values[2]);
|
||||
// TODO: resolve access restriction on ArtifactKey construction
|
||||
currentArtifact = new ArtifactDescriptor(new ArtifactKey(values[0], values[1], version));
|
||||
}
|
||||
|
||||
public ArtifactDescriptor getArtifact() {
|
||||
return currentArtifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String name, Attributes attributes) {
|
||||
if (PROCESSING_STEPS_ELEMENT.equals(name)) {
|
||||
if (processingStepsHandler == null) {
|
||||
processingStepsHandler = new ProcessingStepsHandler(this, attributes);
|
||||
} else {
|
||||
duplicateElement(this, name, attributes);
|
||||
}
|
||||
} else if (PROPERTIES_ELEMENT.equals(name)) {
|
||||
if (propertiesHandler == null) {
|
||||
propertiesHandler = new PropertiesHandler(this, attributes);
|
||||
} else {
|
||||
duplicateElement(this, name, attributes);
|
||||
}
|
||||
} else if (REPOSITORY_PROPERTIES_ELEMENT.equals(name)) {
|
||||
if (repositoryPropertiesHandler == null) {
|
||||
repositoryPropertiesHandler = new PropertiesHandler(this, attributes);
|
||||
} else {
|
||||
duplicateElement(this, name, attributes);
|
||||
}
|
||||
} else {
|
||||
invalidElement(name, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finished() {
|
||||
if (isValidXML() && currentArtifact != null) {
|
||||
Map properties = (propertiesHandler == null ? new OrderedProperties(0) : propertiesHandler.getProperties());
|
||||
currentArtifact.addProperties(properties);
|
||||
|
||||
properties = (repositoryPropertiesHandler == null ? new OrderedProperties(0) : repositoryPropertiesHandler.getProperties());
|
||||
currentArtifact.addRepositoryProperties(properties);
|
||||
|
||||
ProcessingStepDescriptor[] processingSteps = (processingStepsHandler == null ? new ProcessingStepDescriptor[0] //
|
||||
: processingStepsHandler.getProcessingSteps());
|
||||
currentArtifact.setProcessingSteps(processingSteps);
|
||||
artifacts.add(currentArtifact);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class ProcessingStepsHandler extends AbstractHandler {
|
||||
|
||||
private List<ProcessingStepDescriptor> processingSteps;
|
||||
|
||||
public ProcessingStepsHandler(AbstractHandler _parentHandler, Attributes attributes) {
|
||||
super(_parentHandler, PROCESSING_STEPS_ELEMENT);
|
||||
String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE);
|
||||
processingSteps = (size != null ? new ArrayList<ProcessingStepDescriptor>(new Integer(size).intValue()) : new ArrayList<ProcessingStepDescriptor>(4));
|
||||
}
|
||||
|
||||
public ProcessingStepDescriptor[] getProcessingSteps() {
|
||||
return processingSteps.toArray(new ProcessingStepDescriptor[processingSteps.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String name, Attributes attributes) {
|
||||
if (name.equals(PROCESSING_STEP_ELEMENT)) {
|
||||
new ProcessingStepHandler(this, attributes, processingSteps);
|
||||
} else {
|
||||
invalidElement(name, attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class ProcessingStepHandler extends AbstractHandler {
|
||||
|
||||
private final String[] required = new String[] {ID_ATTRIBUTE, STEP_REQUIRED_ATTRIBUTE};
|
||||
private final String[] optional = new String[] {STEP_DATA_ATTRIBUTE};
|
||||
|
||||
public ProcessingStepHandler(AbstractHandler _parentHandler, Attributes attributes, List<ProcessingStepDescriptor> processingSteps) {
|
||||
super(_parentHandler, PROCESSING_STEP_ELEMENT);
|
||||
String[] attributeValues = parseAttributes(attributes, required, optional);
|
||||
processingSteps.add(new ProcessingStepDescriptor(attributeValues[0], attributeValues[1], checkBoolean(PROCESSING_STEP_ELEMENT, STEP_REQUIRED_ATTRIBUTE, attributeValues[2]).booleanValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String name, Attributes attributes) {
|
||||
invalidElement(name, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getErrorMessage() {
|
||||
return Messages.io_parseError;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO:
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
|
||||
import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.AbstractArtifactRepository;
|
||||
|
||||
public class InstallDirArtifactRepository extends AbstractArtifactRepository {
|
||||
|
||||
public static String type = InstallDirArtifactRepository.class.getName();
|
||||
private static String version = "1.0.0";
|
||||
private static String description = "Artifact repository managing installed contents";
|
||||
private static String provider = "Eclipse";
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public InstallDirArtifactRepository(String name, URI location, Map properties) {
|
||||
super(name, type, version, location, description, provider, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IArtifactDescriptor descriptor) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IArtifactKey key) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus getArtifact(IArtifactDescriptor descriptor,
|
||||
OutputStream destination, IProgressMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArtifactKey[] getArtifactKeys() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus getArtifacts(IArtifactRequest[] requests,
|
||||
IProgressMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream(IArtifactDescriptor descriptor)
|
||||
throws ProvisionException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public IStatus getRawArtifact(IArtifactDescriptor descriptor,
|
||||
OutputStream destination, IProgressMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
|
||||
import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.ArtifactRepositoryFactory;
|
||||
|
||||
public class InstallDirArtifactRepositoryFactory extends
|
||||
ArtifactRepositoryFactory {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public IArtifactRepository create(URI location, String name, String type, Map properties) throws ProvisionException {
|
||||
if (InstallDirArtifactRepository.type.equals(type))
|
||||
return new InstallDirArtifactRepository(name, location, properties);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArtifactRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class InstalledFile {
|
||||
|
||||
private final File file;
|
||||
private final long lastModified;
|
||||
|
||||
public InstalledFile(File _file, long _lastModified) {
|
||||
file = _file;
|
||||
lastModified = _lastModified;
|
||||
}
|
||||
|
||||
InstalledFile(String line) {
|
||||
String[] entries = line.split(","); //$NON-NLS-1$
|
||||
if (entries.length < 2) {
|
||||
file = null;
|
||||
lastModified = 0;
|
||||
return;
|
||||
}
|
||||
file = new File(entries[0]);
|
||||
lastModified = Long.parseLong(entries[1]);
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public void uninstall() {
|
||||
if (file != null && file.lastModified() == lastModified) {
|
||||
File f = file;
|
||||
while (f != null && f.delete())
|
||||
f = f.getParentFile();
|
||||
}
|
||||
}
|
||||
|
||||
void write(BufferedWriter out) throws IOException {
|
||||
out.write(file.getAbsolutePath());
|
||||
out.write(',');
|
||||
out.write(String.valueOf(lastModified));
|
||||
out.newLine();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class Messages extends NLS {
|
||||
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.p2.internal.repo.artifact.messages"; //$NON-NLS-1$
|
||||
|
||||
public static String io_failedRead;
|
||||
public static String io_incompatibleVersion;
|
||||
public static String io_parseError;
|
||||
|
||||
static {
|
||||
// initialize resource bundles
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages() {
|
||||
// Do not instantiate
|
||||
}
|
||||
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.apache.tools.bzip2.CBZip2InputStream;
|
||||
import org.apache.tools.tar.TarEntry;
|
||||
import org.apache.tools.tar.TarInputStream;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class TarExtractor extends Thread {
|
||||
|
||||
private final InputStream in;
|
||||
private final File installDir;
|
||||
private final FileListWriter fileListWriter;
|
||||
private final String compression;
|
||||
|
||||
public TarExtractor(InputStream in, File installDir, FileListWriter fileListWriter, String compression) {
|
||||
this.in = in;
|
||||
this.installDir = installDir;
|
||||
this.fileListWriter = fileListWriter;
|
||||
this.compression = compression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
InputStream compIn;
|
||||
if (InstallArtifactRepository.GZIP_COMPRESSION.equals(compression))
|
||||
compIn = new GZIPInputStream(in);
|
||||
else if (InstallArtifactRepository.BZIP2_COMPRESSION.equals(compression)) {
|
||||
// Skip the magic bytes first
|
||||
in.read(new byte[2]);
|
||||
compIn = new CBZip2InputStream(in);
|
||||
} else {
|
||||
// No idea
|
||||
return;
|
||||
}
|
||||
|
||||
TarInputStream tarIn = new TarInputStream(compIn);
|
||||
for (TarEntry tarEntry = tarIn.getNextEntry(); tarEntry != null; tarEntry = tarIn.getNextEntry()) {
|
||||
File outFile = new File(installDir, 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();
|
||||
long lastModified = tarEntry.getModTime().getTime();
|
||||
outFile.setLastModified(lastModified);
|
||||
fileListWriter.addFile(new InstalledFile(outFile, lastModified));
|
||||
}
|
||||
}
|
||||
tarIn.close();
|
||||
fileListWriter.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package org.eclipse.cdt.p2.internal.repo.artifact;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class ZipExtractor extends Thread {
|
||||
|
||||
private final InputStream in;
|
||||
private final File installDir;
|
||||
private final FileListWriter fileListWriter;
|
||||
|
||||
public ZipExtractor(InputStream in, File installDir, FileListWriter fileListWriter) {
|
||||
this.in = in;
|
||||
this.installDir = installDir;
|
||||
this.fileListWriter = fileListWriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ZipInputStream zipIn = new ZipInputStream(in);
|
||||
for (ZipEntry zipEntry = zipIn.getNextEntry(); zipEntry != null; zipEntry = zipIn.getNextEntry()) {
|
||||
File outFile = new File(installDir, zipEntry.getName());
|
||||
if (zipEntry.isDirectory()) {
|
||||
outFile.mkdirs();
|
||||
} else {
|
||||
if (outFile.exists())
|
||||
outFile.delete();
|
||||
else
|
||||
outFile.getParentFile().mkdirs();
|
||||
FileOutputStream outStream = new FileOutputStream(outFile);
|
||||
copyStream(zipIn, false, outStream, true);
|
||||
long lastModified = zipEntry.getTime();
|
||||
outFile.setLastModified(lastModified);
|
||||
fileListWriter.addFile(new InstalledFile(outFile, lastModified));
|
||||
}
|
||||
zipIn.closeEntry();
|
||||
}
|
||||
// Keep reading until there's none left
|
||||
while (in.read() != -1);
|
||||
zipIn.close();
|
||||
fileListWriter.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static int copyStream(InputStream in, boolean closeIn, OutputStream out, boolean closeOut) throws IOException {
|
||||
try {
|
||||
int written = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, len);
|
||||
written += len;
|
||||
}
|
||||
return written;
|
||||
} finally {
|
||||
try {
|
||||
if (closeIn) {
|
||||
in.close();
|
||||
}
|
||||
} finally {
|
||||
if (closeOut) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2008 Wind River Systems and others.
|
||||
# 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:
|
||||
# Doug Schaefer (Wind River) - initial API and implementation
|
||||
###############################################################################
|
||||
|
||||
io_failedRead=Unable to read repository at {0}.
|
||||
io_incompatibleVersion=Install artifact repository has incompatible version {0}; expected {1}.
|
||||
io_parseError=Error parsing install artifact repository.
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.touchpoint;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.p2.internal.repo.artifact.InstallArtifactRepository;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.equinox.internal.p2.artifact.repository.MirrorRequest;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.InstallableUnitOperand;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class CollectAction extends ProvisioningAction {
|
||||
|
||||
public static final String ACTION_NAME = "collect";
|
||||
|
||||
@Override
|
||||
public IStatus execute(Map parameters) {
|
||||
try {
|
||||
InstallableUnitOperand operand = (InstallableUnitOperand)parameters.get("operand");
|
||||
IInstallableUnit installableUnit = operand.second();
|
||||
IProfile profile = (IProfile)parameters.get("profile"); //$NON-NLS-1$
|
||||
|
||||
IArtifactRequest[] requests;
|
||||
IArtifactKey[] toDownload = installableUnit.getArtifacts();
|
||||
if (toDownload == null || toDownload.length == 0)
|
||||
requests = new IArtifactRequest[0];
|
||||
else {
|
||||
IArtifactRepository destination = InstallArtifactRepository.getRepository(profile);
|
||||
requests = new IArtifactRequest[toDownload.length];
|
||||
for (int i = 0; i < toDownload.length; i++)
|
||||
requests[i] = new MirrorRequest(toDownload[i], destination, null, null);
|
||||
}
|
||||
|
||||
Collection artifactRequests = (Collection)parameters.get("artifactRequests");
|
||||
artifactRequests.add(requests);
|
||||
return Status.OK_STATUS;
|
||||
} catch (ProvisionException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus undo(Map parameters) {
|
||||
// No undo
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.p2.internal.touchpoint;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
|
||||
|
||||
public class ExtractAction extends ProvisioningAction {
|
||||
|
||||
public ExtractAction() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus execute(Map parameters) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus undo(Map parameters) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.touchpoint;
|
||||
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.Version;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.Touchpoint;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.ITouchpointType;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class SDKTouchpoint extends Touchpoint {
|
||||
|
||||
public static final ITouchpointType TOUCHPOINT_TYPE = MetadataFactory.createTouchpointType(SDKTouchpoint.class.getName(), new Version("1"));
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* 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:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.p2.internal.touchpoint;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.p2.internal.repo.artifact.InstallArtifactRepository;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
|
||||
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
|
||||
import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction;
|
||||
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
|
||||
|
||||
/**
|
||||
* @author DSchaefe
|
||||
*
|
||||
*/
|
||||
public class UninstallAction extends ProvisioningAction {
|
||||
|
||||
public static final String ACTION_NAME = "uninstall";
|
||||
|
||||
@Override
|
||||
public IStatus execute(Map parameters) {
|
||||
IProfile profile = (IProfile)parameters.get("profile");
|
||||
IArtifactKey artifact = (IArtifactKey)parameters.get("artifact");
|
||||
|
||||
try {
|
||||
IArtifactRepository repo = InstallArtifactRepository.getRepository(profile);
|
||||
repo.removeDescriptor(artifact);
|
||||
} catch (ProvisionException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus undo(Map parameters) {
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue