Skip to content

Commit

Permalink
Upgrade melange 01 2018 (eclipse-gemoc/gemoc-studio#48)
Browse files Browse the repository at this point in the history
Update to latest melange and fix test suites

* [Releng] Change Melange update site to 2018-01-19 build
* use new location of nebula update site
* update fsm sample with latest melange
* wipeout workspace befor building
* try to get more log on test failure
* makes manifest changer more robust

contributes to
#25 and
diverse-project/melange#105

* studio in using oxygen.2
* improve jenkins file

- keep only one artefact per branch*
- set periodic pipeline check

* tee stdout and stderr to for the standard output and  to console

see #49

* add helper.setTargetPlatform in test that fail randomly
* add launch conf in order to ease test devs
* disable concurrent builds
  • Loading branch information
dvojtise authored Feb 17, 2018
1 parent 3567cc1 commit 345b38c
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.PrintStream;

import org.eclipse.gemoc.commons.eclipse.messagingsystem.ui.helper.TeeOutputStream;
import org.eclipse.gemoc.commons.eclipse.messagingsystem.ui.internal.EclipseConsoleOutputStream;
import org.eclipse.gemoc.commons.eclipse.messagingsystem.ui.internal.console.ConsoleIO;
import org.eclipse.gemoc.commons.eclipse.messagingsystem.ui.internal.console.EclipseConsoleIO;
Expand Down Expand Up @@ -106,26 +107,28 @@ public ConsoleIO getConsoleIO() {
return consoleIO;
}

protected PrintStream OriginalSystemOut = null;
protected PrintStream OriginalSystemErr = null;
protected PrintStream originalSystemOut = null;
protected PrintStream originalSystemErr = null;

/**
* set the current System.out and System.err so they are redirected to our
* default console
*/
public void captureSystemOutAndErr() {
Activator.getDefault().getConsoleIO().print("Redirecting System.out and System.err to this console.\n");
if (OriginalSystemOut != System.out) {
OriginalSystemOut = System.out;
PrintStream outPrintStream = new PrintStream(
if (originalSystemOut != System.out) {
originalSystemOut = System.out;
TeeOutputStream teeOutputStream = new TeeOutputStream(
originalSystemOut,
new EclipseConsoleOutputStream(Activator.getDefault().getConsoleIO(), false));
System.setOut(outPrintStream);
System.setOut(new PrintStream(teeOutputStream));
}
if (OriginalSystemErr != System.err) {
OriginalSystemOut = System.out;
PrintStream errPrintStream = new PrintStream(
if (originalSystemErr != System.err) {
originalSystemErr = System.err;
TeeOutputStream teeOutputStream = new TeeOutputStream(
originalSystemErr,
new EclipseConsoleOutputStream(Activator.getDefault().getConsoleIO(), true));
System.setErr(errPrintStream);
System.setErr(new PrintStream(teeOutputStream));
}
}

Expand All @@ -139,12 +142,12 @@ public void releaseSystemOutAndErr() {
System.err.flush();
if(consoleIO != null)
consoleIO.print("Stopping redirection of System.out and System.err to this console.\n");
if (OriginalSystemOut != null)
System.setOut(OriginalSystemOut);
if (OriginalSystemErr != null)
System.setErr(OriginalSystemErr);
OriginalSystemOut = null;
OriginalSystemErr = null;
if (originalSystemOut != null)
System.setOut(originalSystemOut);
if (originalSystemErr != null)
System.setErr(originalSystemErr);
originalSystemOut = null;
originalSystemErr = null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2018 Inria 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:
* Inria - initial API and implementation
*******************************************************************************/
package org.eclipse.gemoc.commons.eclipse.messagingsystem.ui.helper;

import java.io.IOException;
import java.io.OutputStream;

public final class TeeOutputStream extends OutputStream {

private final OutputStream out;
private final OutputStream tee;

public TeeOutputStream(OutputStream out, OutputStream tee) {
if (out == null)
throw new NullPointerException();
else if (tee == null)
throw new NullPointerException();

this.out = out;
this.tee = tee;
}

@Override
public void write(int b) throws IOException {
out.write(b);
tee.write(b);
}

@Override
public void write(byte[] b) throws IOException {
out.write(b);
tee.write(b);
}

@Override
public void write(byte[] b, int off, int len) throws IOException {
out.write(b, off, len);
tee.write(b, off, len);
}

@Override
public void flush() throws IOException {
out.flush();
tee.flush();
}

@Override
public void close() throws IOException {
out.close();
tee.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Map.Entry;
import java.util.jar.Attributes.Name;
import java.util.jar.Manifest;
Expand Down Expand Up @@ -107,7 +110,24 @@ private void writeManifest(IFile outputFile) throws IOException, CoreException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writeManifest(out);
ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
outputFile.setContents(is, 1, new NullProgressMonitor());

try{
if (outputFile.exists()) {
if(!isStreamEqual(is, outputFile.getContents(true))){
// use a new stream because isStreamEqual has used and closed the previous one
outputFile.setContents(new ByteArrayInputStream(out.toByteArray()), true, true, new NullProgressMonitor());
}
} else {
outputFile.create(is, true, new NullProgressMonitor());
}
}
finally{
try {
if (out != null) out.close();
} catch(IOException e) {
//closing quielty
}
}
}
}
public void addPluginDependency(String plugin) throws BundleException, IOException, CoreException {
Expand All @@ -131,4 +151,38 @@ public void addSingleton() throws BundleException, IOException, CoreException {
public void addAttributes(String attributeName, String value){
_manifest.getMainAttributes().putValue(attributeName, value);
}

private static boolean isStreamEqual(InputStream i1, InputStream i2)
throws IOException {

ReadableByteChannel ch1 = Channels.newChannel(i1);
ReadableByteChannel ch2 = Channels.newChannel(i2);

ByteBuffer buf1 = ByteBuffer.allocateDirect(1024);
ByteBuffer buf2 = ByteBuffer.allocateDirect(1024);

try {
while (true) {

int n1 = ch1.read(buf1);
int n2 = ch2.read(buf2);

if (n1 == -1 || n2 == -1) return n1 == n2;

buf1.flip();
buf2.flip();

for (int i = 0; i < Math.min(n1, n2); i++)
if (buf1.get() != buf2.get())
return false;

buf1.compact();
buf2.compact();
}

} finally {
if (i1 != null) i1.close();
if (i2 != null) i2.close();
}
}
}

0 comments on commit 345b38c

Please sign in to comment.