Skip to content

Commit

Permalink
JBIDE-20184 Launching with Java 7 in jbdevstudio.ini results in modul…
Browse files Browse the repository at this point in the history
…e errors in subsequent launches with Java 8
  • Loading branch information
dazarov committed Jul 10, 2015
1 parent d01badd commit 72576ad
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
import java.util.concurrent.LinkedBlockingDeque;

import org.eclipse.core.runtime.ILogListener;
Expand All @@ -32,13 +38,15 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.internal.views.log.LogEntry;
import org.eclipse.ui.internal.views.log.LogSession;
import org.eclipse.ui.internal.views.log.TailInputStream;
import org.eclipse.ui.progress.UIJob;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.service.prefs.BackingStoreException;


public class JVMProblemDetector implements IStartup, ILogListener{
private static final String PREFERENCE_NAME="org.jboss.tools.foundation.checkup.JVMProblemDetector_NOT_TO_SHOW"; //$NON-NLS-1$

Expand Down Expand Up @@ -94,7 +102,14 @@ public void earlyStartup() {

// read error log

readLogFile();
File logFile = Platform.getLogFileLocation().toFile();
if (logFile == null || !logFile.exists()){
try {
readLogFile(new TailInputStream(logFile, MAX_LENGTH));
} catch (IOException e) {
FoundationCheckupPlugin.logError(e);
}
}

// start job which read the queue
job = new JVMProblemDetectorJob();
Expand Down Expand Up @@ -148,16 +163,16 @@ private void checkTestEnvironment(){
testEnvironment = true;
}
}

private void readLogFile() {
File logFile = Platform.getLogFileLocation().toFile();
if (logFile == null || !logFile.exists()){
return;
}
/**
* changed to public for test purpose
* @param InputStream
*/
public void readLogFile(InputStream stream) {

BufferedReader reader = null;
try{
reader = new BufferedReader(new InputStreamReader(new TailInputStream(logFile, MAX_LENGTH), "UTF-8")); //$NON-NLS-1$
reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); //$NON-NLS-1$
while (true) {
String line0 = reader.readLine();
if (line0 == null)
Expand Down Expand Up @@ -218,53 +233,68 @@ private void readQueue(){

private void scanLine(String line){
if (line.startsWith(LogSession.SESSION)) {
Date date = getSessionDate(line);
if(date != null){
currentDate = date;
}
// clear previous data
// call from NOT UI Thread
structure.clear();
moduleNameList.clear();
currentModuleName = null;
} else if (line.startsWith("!ENTRY")) {
Date date = getEntryDate(line);
if(date != null){
currentDate = date;
}
} else if(line.startsWith(STRING_1)){
// parse unresolved module
int position = line.indexOf("[");
String unresolvedModule;
if(position > 0){
unresolvedModule = line.substring(STRING_1.length(), position).trim();
}else{
unresolvedModule = line.substring(STRING_1.length()).trim();
if(isInCurrentSession()){
// parse unresolved module
int position = line.indexOf("[");
String unresolvedModule;
if(position > 0){
unresolvedModule = line.substring(STRING_1.length(), position).trim();
}else{
unresolvedModule = line.substring(STRING_1.length()).trim();
}

moduleNameList.clear();
currentModuleName = unresolvedModule;
}

moduleNameList.clear();
currentModuleName = unresolvedModule;
} else if(line.startsWith(STRING_2)){
// parse unresolved module
int position = line.indexOf(";");
String unresolvedModule;
if(position > 0){
unresolvedModule = line.substring(STRING_2.length(), position).trim();
}else{
unresolvedModule = line.substring(STRING_2.length()).trim();
}

if(currentModuleName != null && !moduleNameList.contains(currentModuleName)){
moduleNameList.add(currentModuleName);
if(isInCurrentSession()){
// parse unresolved module
int position = line.indexOf(";");
String unresolvedModule;
if(position > 0){
unresolvedModule = line.substring(STRING_2.length(), position).trim();
}else{
unresolvedModule = line.substring(STRING_2.length()).trim();
}

if(currentModuleName != null && !moduleNameList.contains(currentModuleName)){
moduleNameList.add(currentModuleName);
}
currentModuleName = unresolvedModule;
}
currentModuleName = unresolvedModule;
} else if(line.startsWith(STRING_3)){
// parse Java name and version
int position = line.indexOf(STRING_4);
if(position > 0){
int endPosition = line.indexOf(")", position+STRING_4.length());

String javaName = line.substring(STRING_3.length(), position).trim();
String javaVersion;
if(endPosition > 0){
javaVersion = line.substring(position+STRING_4.length(), endPosition).trim();
}else{
javaVersion = line.substring(position+STRING_4.length()).trim();
if(isInCurrentSession()){
// parse Java name and version
int position = line.indexOf(STRING_4);
if(position > 0){
int endPosition = line.indexOf(")", position+STRING_4.length());

String javaName = line.substring(STRING_3.length(), position).trim();
String javaVersion;
if(endPosition > 0){
javaVersion = line.substring(position+STRING_4.length(), endPosition).trim();
}else{
javaVersion = line.substring(position+STRING_4.length()).trim();
}
// call from NOT UI Thread
// store unresolved module
structure.addRequieredJava(currentModuleName, moduleNameList, javaName, javaVersion);
}
// call from NOT UI Thread
// store unresolved module
structure.addRequieredJava(currentModuleName, moduleNameList, javaName, javaVersion);
}
}

Expand Down Expand Up @@ -517,4 +547,99 @@ public int hashCode() {
return toString().hashCode();
}
}
}

private long eclipseStartTime = getEclipseStartTime();
private static final DateFormat DATE_FORMATTER = new SimpleDateFormat(LogEntry.F_DATE_FORMAT);
private Date currentDate = null;

/**
* for test purpose
* @param date string in yyyy-MM-dd HH:mm:ss.SSS
* @throws ParseException
*/
public void setEclipseStartTime(String str) throws ParseException{
eclipseStartTime = DATE_FORMATTER.parse(str).getTime();
}

private long getEclipseStartTime() {
String ts = System.getProperty("eclipse.startTime"); //$NON-NLS-1$
try {
return Long.parseLong(ts);
} catch (NumberFormatException e) {
FoundationCheckupPlugin.logError(e);
}
return 0;
}

private boolean isInCurrentSession(){
return currentDate != null && currentDate.getTime() >= eclipseStartTime;
}

private Date getSessionDate(String line) {
line = line.substring(LogSession.SESSION.length()).trim(); // strip "!SESSION "
int delim = line.indexOf("----"); //$NON-NLS-1$
if (delim == -1) {
return null;
}
String dateBuffer = line.substring(0, delim).trim();
try {
return DATE_FORMATTER.parse(dateBuffer);
} catch (ParseException e) {
FoundationCheckupPlugin.logError(e);
}
return null;
}

private Date getEntryDate(String line){
//!ENTRY <pluginID> <severity> <code> <date>
//!ENTRY <pluginID> <date> if logged by the framework!!!
StringTokenizer stok = new StringTokenizer(line, LogEntry.SPACE);
StringBuffer dateBuffer = new StringBuffer();
int tokens = stok.countTokens();
String token = null;
for (int i = 0; i < tokens; i++) {
token = stok.nextToken();
switch (i) {
case 0 :
break;

case 1 :
break;

case 2 :
try {
Integer.parseInt(token);
} catch (NumberFormatException nfe) {
appendToken(dateBuffer, token);
}
break;

case 3 :
try {
Integer.parseInt(token);
} catch (NumberFormatException nfe) {
appendToken(dateBuffer, token);
}
break;

default :
appendToken(dateBuffer, token);
}
}
try{
Date date = DATE_FORMATTER.parse(dateBuffer.toString());
return date;
}catch(ParseException e){
FoundationCheckupPlugin.logError(e);
}
return null;
}

private void appendToken(StringBuffer buffer, String token) {
if (buffer.length() > 0) {
buffer.append(LogEntry.SPACE);
}
buffer.append(token);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
!SESSION 2015-07-07 14:38:03.531 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_09
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments: -product org.eclipse.platform.ide
Command-line arguments: -product org.eclipse.platform.ide -data /home/user/workspaces/workspace/../runtime-JBDS -dev file:/home/user/workspaces/workspace/.metadata/.plugins/org.eclipse.pde.core/JBDS/dev.properties -os linux -ws gtk -arch x86_64 -consoleLog

This is a continuation of log file /home/user/workspaces/runtime-JBDS/.metadata/.bak_0.log
Created Time: 2015-07-07 14:38:14.112

!ENTRY org.jboss.tools.a.a 2 0 2015-07-07 14:41:02.077
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: org.osgi.framework.BundleException: Could not resolve module: org.jboss.tools.c.c.core [1089]
Unresolved requirement: Require-Bundle: org.jboss.tools.b.b
-> Bundle-SymbolicName: org.jboss.tools.b.b; bundle-version="1.7.0.qualifier"; singleton:="true"
org.jboss.tools.b.b [1329]
Unresolved requirement: Require-Bundle: org.jboss.tools.a.a; visibility:="reexport"
-> Bundle-SymbolicName: org.jboss.tools.a.a; bundle-version="1.7.0.qualifier"; singleton:="true"
org.jboss.tools.a.a [1359]
Unresolved requirement: Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=1.8))"

at org.eclipse.osgi.container.Module.start(Module.java:434)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1561)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
!SESSION 2015-07-07 14:38:03.531 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_09
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments: -product org.eclipse.platform.ide
Command-line arguments: -product org.eclipse.platform.ide -data /home/user/workspaces/workspace/../runtime-JBDS -dev file:/home/user/workspaces/workspace/.metadata/.plugins/org.eclipse.pde.core/JBDS/dev.properties -os linux -ws gtk -arch x86_64 -consoleLog

This is a continuation of log file /home/user/workspaces/runtime-JBDS/.metadata/.bak_0.log
Created Time: 2015-07-07 14:38:14.112

!ENTRY org.jboss.tools.a.a 2 0 2015-07-07 14:41:02.077
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: org.osgi.framework.BundleException: Could not resolve module: org.jboss.tools.c.c.core [1089]
Unresolved requirement: Require-Bundle: org.jboss.tools.b.b
-> Bundle-SymbolicName: org.jboss.tools.b.b; bundle-version="1.7.0.qualifier"; singleton:="true"
org.jboss.tools.b.b [1329]
Unresolved requirement: Require-Bundle: org.jboss.tools.a.a; visibility:="reexport"
-> Bundle-SymbolicName: org.jboss.tools.a.a; bundle-version="1.7.0.qualifier"; singleton:="true"
org.jboss.tools.a.a [1359]
Unresolved requirement: Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=1.8))"

at org.eclipse.osgi.container.Module.start(Module.java:434)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1561)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

!SESSION 2015-07-07 15:38:03.531 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_09
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments: -product org.eclipse.platform.ide
Command-line arguments: -product org.eclipse.platform.ide -data /home/user/workspaces/workspace/../runtime-JBDS -dev file:/home/user/workspaces/workspace/.metadata/.plugins/org.eclipse.pde.core/JBDS/dev.properties -os linux -ws gtk -arch x86_64 -consoleLog

This is a continuation of log file /home/user/workspaces/runtime-JBDS/.metadata/.bak_0.log
Created Time: 2015-07-07 15:38:14.112

0 comments on commit 72576ad

Please sign in to comment.