mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-100690 (use build.txt as a fallback if application info is incomplete/unavailable)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,6 +28,8 @@ import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.application.ex.ApplicationInfoEx;
|
||||
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
|
||||
import com.intellij.openapi.components.ExtensionAreas;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
@@ -831,7 +833,11 @@ public class PluginManager {
|
||||
if (ourBuildNumber == null) {
|
||||
ourBuildNumber = BuildNumber.fromString(System.getProperty("idea.plugins.compatible.build"));
|
||||
if (ourBuildNumber == null) {
|
||||
ourBuildNumber = BuildNumber.fromFile();
|
||||
ApplicationInfoEx appInfo = ApplicationInfoImpl.getShadowInstance();
|
||||
ourBuildNumber = appInfo != null ? appInfo.getBuild() : null;
|
||||
if (ourBuildNumber == null) {
|
||||
ourBuildNumber = BuildNumber.fallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ourBuildNumber;
|
||||
|
||||
@@ -13,10 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package com.intellij.openapi.util;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
@@ -27,8 +23,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class BuildNumber implements Comparable<BuildNumber> {
|
||||
private static final String BUILD_NUMBER = "__BUILD_NUMBER__";
|
||||
private static final String SNAPSHOT = "SNAPSHOT";
|
||||
private static final String FALLBACK_VERSION = "999.SNAPSHOT";
|
||||
|
||||
private static final int TOP_BASELINE_VERSION = fromFile().getBaselineVersion();
|
||||
|
||||
private final String myProductCode;
|
||||
@@ -42,7 +44,7 @@ public class BuildNumber implements Comparable<BuildNumber> {
|
||||
}
|
||||
|
||||
public String asString() {
|
||||
return asString(true);
|
||||
return asString(true);
|
||||
}
|
||||
|
||||
public String asStringWithoutProductCode() {
|
||||
@@ -51,10 +53,9 @@ public class BuildNumber implements Comparable<BuildNumber> {
|
||||
|
||||
private String asString(boolean includeProductCode) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (includeProductCode) {
|
||||
if (!StringUtil.isEmpty(myProductCode)) {
|
||||
builder.append(myProductCode).append('-');
|
||||
}
|
||||
|
||||
if (includeProductCode && !StringUtil.isEmpty(myProductCode)) {
|
||||
builder.append(myProductCode).append('-');
|
||||
}
|
||||
|
||||
builder.append(myBaselineVersion).append('.');
|
||||
@@ -63,7 +64,7 @@ public class BuildNumber implements Comparable<BuildNumber> {
|
||||
builder.append(myBuildNumber);
|
||||
}
|
||||
else {
|
||||
builder.append("SNAPSHOT");
|
||||
builder.append(SNAPSHOT);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
@@ -123,29 +124,34 @@ public class BuildNumber implements Comparable<BuildNumber> {
|
||||
}
|
||||
|
||||
private static int parseBuildNumber(String version, String code, String name) {
|
||||
if ("SNAPSHOT".equals(code) || BUILD_NUMBER.equals(code)) {
|
||||
if (SNAPSHOT.equals(code) || BUILD_NUMBER.equals(code)) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(code);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
throw new RuntimeException("Invalid version number: " + version +"; plugin name: " + name);
|
||||
throw new RuntimeException("Invalid version number: " + version + "; plugin name: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
public static BuildNumber fromFile() {
|
||||
String text = "999.SNAPSHOT";
|
||||
private static BuildNumber fromFile() {
|
||||
try {
|
||||
final String homePath = PathManager.getHomePath();
|
||||
final File buildTxtFile = FileUtil.findFirstThatExist(homePath + "/build.txt", homePath + "/community/build.txt");
|
||||
if (buildTxtFile != null) {
|
||||
text = FileUtil.loadFile(buildTxtFile).trim();
|
||||
String text = FileUtil.loadFile(buildTxtFile).trim();
|
||||
return fromString(text);
|
||||
}
|
||||
}
|
||||
catch (IOException ignored) { }
|
||||
catch (IOException ignored) {
|
||||
}
|
||||
|
||||
return fromString(text);
|
||||
return fallback();
|
||||
}
|
||||
|
||||
public static BuildNumber fallback() {
|
||||
return fromString(FALLBACK_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,6 +203,7 @@ public class BuildNumber implements Comparable<BuildNumber> {
|
||||
if (bn == Integer.MAX_VALUE) {
|
||||
return TOP_BASELINE_VERSION; // SNAPSHOTS
|
||||
}
|
||||
|
||||
if (bn >= 10000) {
|
||||
return 88; // Maia, 9x builds
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,20 +13,24 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package com.intellij.openapi.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BuildNumberTest extends TestCase {
|
||||
public void testHistoricBuild() {
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class BuildNumberTest {
|
||||
@Test
|
||||
public void historicBuild() {
|
||||
assertEquals(new BuildNumber("", 75, 7512), BuildNumber.fromString("7512"));
|
||||
}
|
||||
|
||||
public void testSnapshotDominates() {
|
||||
|
||||
@Test
|
||||
public void snapshotDomination() {
|
||||
assertTrue(BuildNumber.fromString("90.SNAPSHOT").compareTo(BuildNumber.fromString("90.12345")) > 0);
|
||||
assertTrue(BuildNumber.fromString("IU-90.SNAPSHOT").compareTo(BuildNumber.fromString("RM-90.12345")) > 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user