Search in sources :

Example 6 with ExtensibleURIConverterImpl

use of org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl in project xtext-eclipse by eclipse.

the class PersistableResourceDescriptionsTest method setUp.

@Before
public void setUp() throws Exception {
    fileSystem = Maps.newHashMap();
    builderState = builderInjector.getInstance(ClusteringBuilderState.class);
    uriConverter = new ExtensibleURIConverterImpl() {

        @Override
        public InputStream createInputStream(org.eclipse.emf.common.util.URI uri, Map<?, ?> options) throws IOException {
            return new StringInputStream(fileSystem.get(uri.toString()));
        }
    };
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) ClusteringBuilderState(org.eclipse.xtext.builder.clustering.ClusteringBuilderState) URI(org.eclipse.emf.common.util.URI) StringInputStream(org.eclipse.xtext.util.StringInputStream) InputStream(java.io.InputStream) ExtensibleURIConverterImpl(org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl) IOException(java.io.IOException) Before(org.junit.Before)

Example 7 with ExtensibleURIConverterImpl

use of org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelExporter method exportModel.

/**
 * Export the IArchimateModel as Grafico files
 * @throws IOException
 */
public void exportModel() throws IOException {
    // Define target folders for model and images
    // Delete them and re-create them (remark: FileUtils.deleteFolder() does sanity checks)
    File modelFolder = new File(fLocalRepoFolder, IGraficoConstants.MODEL_FOLDER);
    FileUtils.deleteFolder(modelFolder);
    modelFolder.mkdirs();
    File imagesFolder = new File(fLocalRepoFolder, IGraficoConstants.IMAGES_FOLDER);
    FileUtils.deleteFolder(imagesFolder);
    imagesFolder.mkdirs();
    // Save model images (if any): this has to be done on original model (not a copy)
    saveImages();
    // Create ResourceSet
    fResourceSet = new ResourceSetImpl();
    // $NON-NLS-1$
    fResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMLResourceFactoryImpl());
    // Add a URIConverter that will be used to map full filenames to logical names
    fResourceSet.setURIConverter(new ExtensibleURIConverterImpl());
    // Now work on a copy
    IArchimateModel copy = EcoreUtil.copy(fModel);
    // Create directory structure and prepare all Resources
    createAndSaveResourceForFolder(copy, modelFolder);
    // Now save all Resources
    int maxThreads = ModelRepositoryPlugin.INSTANCE.getPreferenceStore().getInt(IPreferenceConstants.PREFS_EXPORT_MAX_THREADS);
    // $NON-NLS-1$
    JobGroup jobgroup = new JobGroup("GraficoModelExporter", maxThreads, 1);
    final ExceptionProgressMonitor pm = new ExceptionProgressMonitor();
    for (Resource resource : fResourceSet.getResources()) {
        Job job = new // $NON-NLS-1$
        Job(// $NON-NLS-1$
        "Resource Save Job") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    resource.save(null);
                } catch (IOException ex) {
                    pm.catchException(ex);
                }
                return Status.OK_STATUS;
            }
        };
        job.setJobGroup(jobgroup);
        job.schedule();
    }
    try {
        jobgroup.join(0, pm);
    } catch (OperationCanceledException | InterruptedException ex) {
        throw new IOException(ex);
    }
    // Throw on any exception
    if (pm.ex != null) {
        throw pm.ex;
    }
}
Also used : JobGroup(org.eclipse.core.runtime.jobs.JobGroup) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMLResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExtensibleURIConverterImpl(org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

ExtensibleURIConverterImpl (org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl)7 IOException (java.io.IOException)4 URIConverter (org.eclipse.emf.ecore.resource.URIConverter)4 InputStream (java.io.InputStream)3 URI (org.eclipse.emf.common.util.URI)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 IArchimateModel (com.archimatetool.model.IArchimateModel)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 ZipInputStream (java.util.zip.ZipInputStream)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobGroup (org.eclipse.core.runtime.jobs.JobGroup)1 EPackage (org.eclipse.emf.ecore.EPackage)1