Commit 4b91f00b authored by Dominique Marcadet's avatar Dominique Marcadet

Initial import in new git repositories

parent e3f2ba7b
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>fr.centralesupelec.edf.riseclipse.main</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: RiseClipse Main Plugin
Bundle-SymbolicName: fr.centralesupelec.edf.riseclipse.main;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: CentraleSupélec & EDF
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.emf.common,
org.eclipse.emf.ecore,
org.eclipse.emf.ecore.xmi
Export-Package: fr.centralesupelec.edf.riseclipse.util
#
# Copyright (c) 2017 CentraleSupélec & EDF.
# 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
#
# This file is part of the RiseClipse tool
#
# Contributors:
# Computer Science Department, CentraleSupélec : initial implementation
# Contacts:
# Dominique.Marcadet@centralesupelec.fr
#
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<!--
Copyright (c) 2017 CentraleSupélec & EDF.
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
This file is part of the RiseClipse tool
Contributors:
Computer Science Department, CentraleSupélec : initial implementation
Contacts:
Dominique.Marcadet@centralesupelec.fr
-->
<plugin>
<extension-point id="meta_models" name="Metamodels for RiseClipse" schema="schema/fr.centralesupelec.edf.riseclipse.exsd"/>
</plugin>
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="fr.centralesupelec.edf.riseclipse" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="fr.centralesupelec.edf.riseclipse" id="meta_models" name="Metamodels for RiseClipse"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="meta_model" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="meta_model">
<annotation>
<appinfo>
<meta.element labelAttribute="name"/>
</appinfo>
</annotation>
<complexType>
<attribute name="uri" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="adapterFactory" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.emf.common.notify.AdapterFactory"/>
</appinfo>
</annotation>
</attribute>
<attribute name="resourceFactory" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.emf.ecore.resource.Resource$Factory"/>
</appinfo>
</annotation>
</attribute>
<attribute name="viewerFilter" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn="org.eclipse.jface.viewers.ViewerFilter:"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="copyright"/>
</appinfo>
<documentation>
Copyright (c) 2017 CentraleSupélec &amp; EDF.
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
This file is part of the RiseClipse tool
Contributors:
Computer Science Department, CentraleSupélec : initial implementation
Contacts:
Dominique.Marcadet@centralesupelec.fr
</documentation>
</annotation>
</schema>
/**
* Copyright (c) 2017 CentraleSupélec & EDF.
* 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
*
* This file is part of the RiseClipse tool
*
* Contributors:
* Computer Science Department, CentraleSupélec : initial implementation
* Contacts:
* Dominique.Marcadet@centralesupelec.fr
*/
package fr.centralesupelec.edf.riseclipse.util;
/**
* Base class for RiseClipse consoles.
* It implements the Singleton design pattern, handle the level of messages
* and prefixes each message with the level name.
*
* @author Dominique Marcadet
*
*/
public abstract class AbstractRiseClipseConsole implements IRiseClipseConsole {
/**
* The unique instance of AbstractRiseClipseConsole
*/
protected static IRiseClipseConsole console;
/**
* Give access to the singleton.
* It creates a {@link TextRiseClipseConsole} if there is none.
*
* @return The unique instance of AbstractRiseClipseConsole
*/
public static synchronized IRiseClipseConsole getConsole() {
if( console == null ) {
console = new TextRiseClipseConsole();
}
return console;
}
/**
* The current level of displayed messages
*/
protected int currentLevel;
/**
* Constructs a new console, using it as the unique one
* (the previous one, if any, is forgotten).
* The initial level is set to {@link IRiseClipseConsole#INFO_LEVEL}
*/
protected AbstractRiseClipseConsole() {
console = this;
currentLevel = INFO_LEVEL;
}
/**
* Basic implementation of {@link IRiseClipseConsole#setLevel(int)}
*/
public int setLevel( int level ) {
int previousLevel = currentLevel;
if(( level >= INFO_LEVEL ) && ( level <= FATAL_LEVEL )) {
currentLevel = level;
}
return previousLevel;
}
/**
* Prefixes message with INFO and delegates to {@link AbstractRiseClipseConsole#doOutputMessage(String)}
* if current level is {@link #INFO_LEVEL}
*/
public final void info( Object o ) {
if( currentLevel <= INFO_LEVEL ) {
doOutputMessage( "INFO: " + o.toString() );
}
}
/**
* Prefixes message with WARNING and delegates to {@link AbstractRiseClipseConsole#doOutputMessage(String)}
* if current level is {@link #WARNING_LEVEL} or below
*/
public final void warning( Object o ) {
if( currentLevel <= WARNING_LEVEL ) {
doOutputMessage( "WARNING: " + o.toString() );
}
}
/**
* Prefixes message with ERROR and delegates to {@link AbstractRiseClipseConsole#doOutputMessage(String)}
* if current level is {@link #ERROR_LEVEL} or below
*/
public final void error( Object o ) {
if( currentLevel <= ERROR_LEVEL ) {
doOutputMessage( "ERROR: " + o.toString() );
}
}
/**
* Prefixes message with FATAL and delegates to {@link AbstractRiseClipseConsole#doOutputMessage(String)},
* then throws a {@link RiseClipseFatalException}
*/
public final void fatal( Object o ) {
doOutputMessage( "FATAL: " + o.toString() );
throw new RiseClipseFatalException( "FATAL: " + o.toString(), null );
}
/**
* Output message s on the current console
* @param m message to display
*/
protected abstract void doOutputMessage( String m );
}
/**
* Copyright (c) 2017 CentraleSupélec & EDF.
* 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
*
* This file is part of the RiseClipse tool
*
* Contributors:
* Computer Science Department, CentraleSupélec : initial implementation
* Contacts:
* Dominique.Marcadet@centralesupelec.fr
*/
package fr.centralesupelec.edf.riseclipse.util;
/**
* Interface for outputting messages to users.
* It defines four increasing levels of messages and allows
* for choosing the minimal level of displayed messages.
*
* @author Dominique Marcadet
*
*/
public interface IRiseClipseConsole {
public final static int INFO_LEVEL = 1;
public final static int WARNING_LEVEL = 2;
public final static int ERROR_LEVEL = 3;
public final static int FATAL_LEVEL = 4;
/**
* Set the current level of displayed messages.
*
* @param level minimal level of messages to be displayed,
* ignored if outside [INFO_LEVEL..FATAL_LEVEL]
* @return the previous level
*/
public int setLevel( int level );
/**
* Output message o.toString() if current level is INFO_LEVEL
*
* @param o message to be displayed
*/
public void info( Object o );
/**
* Output message o.toString() if current level is WARNING_LEVEL or below
*
* @param o message to be displayed
*/
public void warning( Object o );
/**
* Output message o.toString() if current level is ERROR_LEVEL or below
*
* @param o message to be displayed
*/
public void error( Object o );
/**
* Output message o.toString() if current level is FATAL_LEVEL or below
*
* @param o message to be displayed
*/
public void fatal( Object o );
}
/**
* Copyright (c) 2017 CentraleSupélec & EDF.
* 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
*
* This file is part of the RiseClipse tool
*
* Contributors:
* Computer Science Department, CentraleSupélec : initial implementation
* Contacts:
* Dominique.Marcadet@centralesupelec.fr
*/
package fr.centralesupelec.edf.riseclipse.util;
public interface IRiseClipseResource {
void printStatistics( IRiseClipseConsole console );
void finalizeLoad( boolean ignore_unresolved_reference );
}
/**
* Copyright (c) 2017 CentraleSupélec & EDF.
* 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
*
* This file is part of the RiseClipse tool
*
* Contributors:
* Computer Science Department, CentraleSupélec : initial implementation
* Contacts:
* Dominique.Marcadet@centralesupelec.fr
*/
package fr.centralesupelec.edf.riseclipse.util;
/**
* This class is for fatal exceptions in RiseClipse, they must
* not be caught.
*
* @author Dominique Marcadet
*
*/
public class RiseClipseFatalException extends RiseClipseRuntimeException {
private static final long serialVersionUID = 1L;
public RiseClipseFatalException( String error, Exception e ) {
super( error, e );
}
}
/**
* Copyright (c) 2017 CentraleSupélec & EDF.
* 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
*
* This file is part of the RiseClipse tool
*
* Contributors:
* Computer Science Department, CentraleSupélec : initial implementation
* Contacts:
* Dominique.Marcadet@centralesupelec.fr
*/
package fr.centralesupelec.edf.riseclipse.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.IllegalValueException;
import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole;
public abstract class RiseClipseModelLoader {
protected ResourceSetImpl resourceSet;
protected IRiseClipseConsole console;
protected RiseClipseModelLoader( IRiseClipseConsole console ) {
this.console = console;
// Create a resource set to hold the resources.
this.resourceSet = new ResourceSetImpl();
}
public ResourceSet getResourceSet() {
return resourceSet;
}
public Resource load( String name ) {
console.info( "Loading: " + name );
int currentSize = resourceSet.getResources().size();
// Construct the URI for the instance file.
// The argument is treated as a file path only if it denotes an existing file.
// Otherwise, it's directly treated as a URL.
File file = new File( name );
URI uri = file.isFile() ? URI.createFileURI( file.getAbsolutePath() ) : URI.createURI( name );
ArrayList< URI > resourceURIs = new ArrayList< URI >();
resourceURIs.add( uri );
try {
ZipInputStream in = new ZipInputStream( resourceSet.getURIConverter().createInputStream( resourceURIs.get( 0 )));
ZipEntry entry = in.getNextEntry();
if( entry != null ) {
String zipURI = resourceURIs.get( 0 ).toString();
resourceURIs.clear();
while( entry != null ) {
// Must use "archive:" and not "zip:" to be recognized by ArchiveURIHandlerImpl
resourceURIs.add( URI.createURI( "archive:" + zipURI + "!/" + entry.getName() ));
entry = in.getNextEntry();
}
}
in.close();
}
catch( IOException e ) {
// Will be handled later
}
for( URI resourceURI : resourceURIs ) {
try {
// Load the resource through the editing domain.
//
@SuppressWarnings("unused")
Resource resource = resourceSet.getResource( resourceURI, true );
}
// This is done by RiseClipseModelLoader in the command line tool
catch( RuntimeException re ) {
Throwable cause = re.getCause();
if( cause instanceof IllegalValueException ) {
IllegalValueException e = ( IllegalValueException ) cause;
console.error( "value " + e.getValue() + " is not legal at line " + e.getLine() + " for feature "
+ e.getFeature().getName() + ", it should be " + e.getFeature().getEType().getInstanceTypeName() );
}
else if( cause instanceof FileNotFoundException ) {
console.error( "Problem loading " + resourceURI + " : file not found" );
// Resource has been created !
// We remove it to return null
if( resourceSet.getResources().size() > currentSize ) {
resourceSet.getResources().remove( currentSize );
}
}
else {
console.error( "Problem loading " + resourceURI + " : " + cause );
}
}
catch( Exception e ) {
console.error( "Problem loading " + resourceURI + " : " + e );
}
}
// resourceSet.getResource() return the resource.
// But if an exception occurs, we don't get it !
// So, we expect that the newly created resource is the last one
// in the resourceSet.
if( resourceSet.getResources().size() > currentSize ) {
return resourceSet.getResources().get( currentSize );
}
return null;
}
}
/**
* Copyright (c) 2017 CentraleSupélec & EDF.
* 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
*
* This file is part of the RiseClipse tool
*
* Contributors:
* Computer Science Department, CentraleSupélec : initial implementation
* Contacts:
* Dominique.Marcadet@centralesupelec.fr
*/
package fr.centralesupelec.edf.riseclipse.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Factory;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class RiseClipseResourceSet extends ResourceSetImpl {
private HashMap< String, Factory > resourceFactories;
private ResourceFactoryFinder factoryFinder;
public RiseClipseResourceSet( HashMap< String, Resource.Factory > resourceFactories ) {
this.resourceFactories = resourceFactories;
this.factoryFinder = new ResourceFactoryFinder();
}
@Override
public Resource createResource( URI uri,